October
29th,
2012
Bjarne Stroustrup, the creator of C++, said recently that C++11 “feels
like a new language — the pieces just fit together better.”
Indeed, core C++11 has changed significantly.
Indeed, core C++11 has changed significantly.
New features include:
- lambda expressions
- automatic type deduction of objects
- uniform initialization syntax
- delegating constructors
- deleted and defaulted function declarations
-
nullptr
- rvalue references
An example: suppose that v is a vector:
and we want to call a function foo on each element of v. In C++03, we might do so this way:
A more sophisticated style is to use an iterator, thereby avoiding what would otherwise be a dependency on the
ability to use subscripts:
If we are to write this code fragment to take advantage of C++11, we might well do so differently. For example, we
might write the first example this way:
but we would be more likely to write something like this:
or even like this:
Looks like we moving towards interpreted languages…
Sources: