12 Replies - 9036 Views - Last Post: 03 June 2012 - 07:19 PM Rate Topic: -----

#1 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Moving toward C++11

Post icon  Posted 27 March 2012 - 03:26 PM

*
POPULAR

So as many of you know C++11 was ratified late in 2011 and compiler support is well on it's way. Most major compilers have several features implemented and I would like to move towards using those features in the forums as they become available to us. If you are helping in the forums I would encourage you to show how to use new features of C++11 to solve problems in your posts.

C++11 has many new features and libraries that make it "feel like a new language"(Bjarne Stroustrup). These features will help reduce bugs, produce even more flexible code, and make everyone's lives easier overall. It's nearly 100% backward compatible so your old code shouldn't need to be modified. C++11 even makes your old code faster! Rvalue references and move semantics can be taken advantage of by old programs without modifying *anything* simply by having used the standard library. Lambdas, nullptr, type deduction, smart pointers, regexs, and multithreading are some of the other big features. I think you'll ]be glad you learned to use the new features. if you're still not convinced, read this link.

A quick list of some new features and the problems they solve:
  • 'auto' keyword - This keyword as been changed meaning from linkage to type deduction. No more long obtuse iterator types, just use 'auto'.
  • smart pointers - Sometimes you need garbage collection or something similar. Smart pointers have you mostly covered.
  • regex - you don't need external libraries anymore. it's in the standard now and the implementation is high quality.
  • multithreading! - no more system specific code, difficult low level thread handles and functions, or lack of language support. C++ now is built with threading in mind and a library to help you do it



The following features are already in both GCC 4.6(with option -std=C++0x) and VC10 so we can start using them now:
  • nullptr(pdf) - No more integer, pointer confusion. nullptr takes care of that. No more using NULL, it's evil. nullptr is the solution.
  • right angle brackets - You don't have to put spaces in between your template delimiters any more.
  • static_assert - You can now make assertions at compile time. you don't have to use boost for this anymore.
  • lambdas(pdf) - No more writing whole classes for simple predicates. just use a lambda. VC10 has most of the support but a few 'edge cases' are incorrect because they implemented before these cases were defined. GCC has full support for them.
  • long long(pdf) - You can now use long long and unsigned long long in your code; it's official now.
    hash tables - You now no longer need a less than predicate to store values in associative containers and you can get O(1) access and write times to boot! std::unordered_map and friends implement associative containers with hash_tables semantics. instead of a less than predicate these containers require an equality predicate and hash function.
    tuple - No need to make structures every time you need to store more than 2 items in a singile unit. tuples allow arbitrarily many independent elements to be passed around as a single coherent unit.


GCC has *many* more C++11 features than VC10 as it stands right now. GCC 4.7 is out and you can use C++11 with option '-std=C++11'. GCC 4.7 has even more of the language and standard library implemented. you can see the full list of C++11 support for GCC here. VC11 will have more C++11 features and will be coming out soon.

I will update this list as compiler support increases. I would encourage everyone to use as many of your compiler's C++11 features as possible. here is a large list of compiler support by various compilers.

Is This A Good Question/Topic? 6
  • +

Replies To: Moving toward C++11

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3988
  • View blog
  • Posts: 12,301
  • Joined: 25-December 09

Re: Moving toward C++11

Posted 27 March 2012 - 04:51 PM

Quote

GCC 4.7 is out and you can use C++11 with option '-std=C++11'.

True, but don't forget that gcc 4.7 is considered a development version and may not be stable. The 4.6 version is the current stable version.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Moving toward C++11

Posted 27 March 2012 - 06:08 PM

I believe it was declared stable on March 22 2012. 4.8 is in "Active Development" now. see this link. I may be misreading it however.

This post has been edited by ishkabible: 27 March 2012 - 06:11 PM

Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 3988
  • View blog
  • Posts: 12,301
  • Joined: 25-December 09

Re: Moving toward C++11

Posted 27 March 2012 - 06:26 PM

That looks correct, I'm about a week behind the times. Downloaded 4.7 last week and it was still the development branch.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 Seta00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 84
  • Joined: 22-September 10

Re: Moving toward C++11

Posted 28 March 2012 - 08:15 AM

Don't forget about Clang, its C++0x/C++11 support has always been ahead of the "competition".

libc++ is also worth checking out :)
Was This Post Helpful? 0
  • +
  • -

#6 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 651
  • View blog
  • Posts: 2,225
  • Joined: 31-December 10

Re: Moving toward C++11

Posted 28 March 2012 - 08:37 AM

View PostSeta00, on 28 March 2012 - 11:15 AM, said:

Don't forget about Clang, its C++0x/C++11 support has always been ahead of the "competition".

libc++ is also worth checking out :)

Lately I've been trying to learn how to use LLVM and also Clang. I have to say that I really like the non-cryptic warnings/errors (pretty-print) that Clang outputs when compiling programs. Especially any template warnings/errors, it can be very helpful.
Was This Post Helpful? 0
  • +
  • -

#7 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: Moving toward C++11

Posted 28 March 2012 - 08:54 AM

Move semantics and rvalue references really changes the way you think. Whenyou finally find yourself using it naturally it's amazing.

Another amazing thing feature is constexpr. While programming in C# (that is such a sweet language in terms of features) you find yourself getting a lot of annoying 'must be a compile-time constant'.
Was This Post Helpful? 0
  • +
  • -

#8 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Moving toward C++11

Posted 28 March 2012 - 10:19 AM

View PostSeta00, on 28 March 2012 - 04:15 PM, said:

Don't forget about Clang, its C++0x/C++11 support has always been ahead of the "competition".

libc++ is also worth checking out :)


I provided a link for many different compiler's support for C++11 features to cover the slightly less popular compilers. Also, GCC currently has more C++11 features.
Was This Post Helpful? 0
  • +
  • -

#9 trvr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 09-March 09

Re: Moving toward C++11

Posted 01 April 2012 - 01:53 PM

Are there any reference resources available for someone who is just starting to pick-up C++ that are updated for C++11? I have experience with Java, but I would like to expand my knowledge base to C++ as my new primary language of choice for various reasons.
Was This Post Helpful? 0
  • +
  • -

#10 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Moving toward C++11

Posted 01 April 2012 - 03:37 PM

cppreference seems to have the best C++11 reference right now. other sites like cplusplus haven't updated everything just yet.
Was This Post Helpful? 0
  • +
  • -

#11 ymm1030  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-April 12

Re: Moving toward C++11

Posted 22 April 2012 - 05:10 AM

Amazing!I think java will be fully influenced.
Was This Post Helpful? 0
  • +
  • -

#12 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 651
  • View blog
  • Posts: 2,225
  • Joined: 31-December 10

Re: Moving toward C++11

Posted 31 May 2012 - 10:19 AM

Just saw this article/tutorial on drdobbs.com about C++11 threading support, specifically the "async" template.
Was This Post Helpful? 0
  • +
  • -

#13 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: Moving toward C++11

Posted 03 June 2012 - 07:19 PM

just I note becuase I was looking though GCC support:
short of inheriting constructors, rvalue references for *this, 'alignas', attributes ('[[blah, blah]]), and full concurrency support(GCC has very little right now) GCC fully implements C++11. the libraries are fully implemented however you just get some non-standard behavoir if you use any of the unimplemented features.

VC++ should come out with a near fully complaint compiler this year too so C++11 compiler support will be here quickly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1