C++11: A cheat sheet—Alex Sinyakov

Save to:
Instapaper Pocket Readability

Want a quick "cheat sheet" overview of what's new in C++11? Alex Sinyakov recently gave a presentation on this topic and has posted slides that are useful as a capsule summary in flash card form:

C++11 (PDF slides)

Alex Sinyakov, AMC Bridge LLC

Slide after slide shows C++11 code side by side with the same code written in older C++ style or in other languages. You'll quickly notice a pattern: In example after example, C++11 code is clean, safe, and as fast as ever... and sometimes even faster.

As Bjarne Stroustrup puts it: "Surprisingly, C++11 feels like a new language: The pieces just fit together better than they used to and I find a higher-level style of programming more natural than before and as efficient as ever."

Enjoy these great quick study notes as a refresher before your next C++11 interview.

For a detailed treatment of what’s new in C++11, see Overview of the New C++ (C++11) by Scott Meyers, featured on our Get Started! page. These are Scott’s fully-annotated color training materials from his course of the same name, and the best current approximation of “a book on what’s new in C++11.” (Free sample available.)

Add a Comment

You must sign in or register to add a comment.

Comments (9)

1 0

FaTony said on Dec 26, 2012 02:58 PM:

Looks like there's a typo in delegating constructors slide. Author writes X when he meant A.
1 0

Alex Sinyakov said on Dec 26, 2012 03:53 PM:

FaTony, thank you.
here is corrected version: http://sdrv.ms/W2pck2
Admin, please, re-upload.
1 0

Alex Sinyakov said on Dec 27, 2012 04:52 AM:

fixed. Please, let me know if you find any other typos!
thx.
1 1

Zenju said on Dec 27, 2012 05:03 AM:

Using "auto" everywhere possible is like using the word "stuff" in every sentence instead of the proper term. Sure one can deduce what was meant, but readability suffers because "something" is meaningless without context. Redundancy facilitates understanding, especially for humans...
1 0

Ioannis Vranos said on Dec 27, 2012 10:41 AM:

Few corrections and notes regarding C++03 examples.

Site screenshot, and page 27:

C++03:

int a[]= {1, 2, 3, 4, 5};

// or vector<int> v(a, a+5);
vector<int> v(a, a+ sizeof(a)/sizeof(*a));

----------------------------------------------------------------


Pages 2-3:

In C++03, instead of

foo(NULL);


foor(0) is prefered .


However the point is the same, nullptr is better.



Pages 4-5:

In C++03 the following applies:

sizeof(char) == sizeof(unsigned char)== sizeof(signed char)==1 byte (== numeric_limits<unsigned char>::digits bits)



Page 11:

C++03 provides assert() for run-time assertions, in <cassert>, <assert.h>.

The template function could be implemented as:

template<class T>
void f(T v)
{
assert(sizeof(v)==4);

//do something with v
}


Of course, C++11 compile-time assertion is better.


Pages 15-17: C++03 provides pointers to functions and member functions, but C++11 new keywords are probably better.


Page 45: In C++03 0xD0U is hexadecimal unsigned, not 0xD0.


Page 51: The last line of C++03 code, in a clearer format:

// or, sort(a, a + sizeof(a)/sizeof(a[0]));
sort( a, a + sizeof(a)/sizeof(*a));
0 0

Ioannis Vranos said on Dec 27, 2012 10:44 AM:

Few corrections and notes regarding C++03 examples:

http://cppsoftware.binhoster.com/documents/cpp03_corrections_and_notes.txt
0 0

Ioannis Vranos said on Dec 28, 2012 07:45 AM:

A couple of corrections, and notes regarding C++03 examples.

Site screenshot, and page 27:

C++03:

int a[]= {1, 2, 3, 4, 5};

// or vector<int> v(a, a+5);
vector<int> v(a, a+ sizeof(a)/sizeof(*a));




Pages 2-3:

In C++03, instead of

foo(NULL);



foo(0);
is preferred.


However the point is the same, nullptr is better.



Pages 4-5:

In C++03 the following applies:

sizeof(char) == sizeof(unsigned char)== sizeof(signed char)==1 byte (== numeric_limits<unsigned char>::digits   bits)




Page 11:

C++03 provides assert() for run-time assertions, in <cassert>, <assert.h>.

The template function could be implemented as:

template<class T>
void f(T v)
{
assert(sizeof(v)==4);

//do something with v
}



Of course, C++11 compile-time assertion is better.


Pages 15-17: C++03 provides pointers to functions and member functions, but C++11 new keywords are probably better.


Page 45: In C++03 0xD0U, and 0xD0u, is hexadecimal unsigned, not 0xD0.


Page 51: The last line of C++03 code, in a clearer format:

// or, sort(a, a + sizeof(a)/sizeof(a[0])); 
sort(a, a + sizeof(a)/sizeof(*a));
0 0

Ioannis Vranos said on Dec 28, 2012 07:47 AM:

I think the forum needs better formatting tools for comments.
0 0

Cassio Neri said on Jan 5, 2013 10:39 AM:

I'm a big fan of "auto" but the guideline that says to use prefer using it in

auto p = new T();

is wrong. Indeed, the type of p is T* and, most likely, the programmer want it to be a smart pointer like, say, unique_ptr<T>. While waiting the standardization of make_unique, one should use

unique_ptr<T> p = new T();

On the other hand,

auto p = make_shared<T>(arg1);

is right because make_shared<T> returns a shared_ptr<T>.