C 2011 IN HASTE A quick tour of

  • Slides: 17
Download presentation
C++ 2011 IN HASTE A quick tour of all the new features in the

C++ 2011 IN HASTE A quick tour of all the new features in the 2011 C++ Standard (C) 2011 Alisdair Meredith 1

A Quick History Lesson C++98 C++03 TR 1 C++11 • Initial Standard • ~7

A Quick History Lesson C++98 C++03 TR 1 C++11 • Initial Standard • ~7 years • Revised standard • Limited to bug fixing • ~ 5 years • Pure library extension • ~3 years • Significant new features to language and library • Many more bug fixes than C++03 • ~8 years work (C) 2011 Alisdair Meredith 2

Standards Process � � Work under auspices of ISO SC 22 WG 21 Typically

Standards Process � � Work under auspices of ISO SC 22 WG 21 Typically 5 -10 national bodies present at any meeting � More � participants online Meet 2 -3 times a year for week-long meetings � Typical attendance in 50 -100 range � 4 active working groups � Core Library Evolution Concurrency Work continues online at a slower pace (C) 2011 Alisdair Meredith 3

Changes What’s new? What’s changed? • > 50 New Language Features • New Libraries

Changes What’s new? What’s changed? • > 50 New Language Features • New Libraries • Built on top of a wider set of standards • Revised Library for new language • Resolved several hundred defect reports • Cleaned up presentation (C) 2011 Alisdair Meredith 4

What was missed? � � � Concepts Modules Reflection Full-featured Garbage Collection “No New

What was missed? � � � Concepts Modules Reflection Full-featured Garbage Collection “No New libraries (beyond TR 1)” TR 1 math libraries � Becomes its own standard instead (C) 2011 Alisdair Meredith 5

What was removed � � export auto to declare local variables access declarations Conversion

What was removed � � export auto to declare local variables access declarations Conversion from string literal to ‘char *’ � Converts � only to ‘char const *’ now Reference counted strings (C) 2011 Alisdair Meredith 6

Embrace Standards � � C 99 + TC 1 + TC 2 + Unicode

Embrace Standards � � C 99 + TC 1 + TC 2 + Unicode TR Unicode ECMAscript regular expressions Posix � error handling � threads (C) 2011 Alisdair Meredith 7

Concurrency New Memory Model Low level primitives High level primitives • Define race conditions

Concurrency New Memory Model Low level primitives High level primitives • Define race conditions • Limit optimisations within a single thread • Thread local storage • Parallel initialization/shutdown • atomic operations and fences • thread wrappers • Mutexes and locks • Futures • asynch (C) 2011 Alisdair Meredith 8

Language Updates Incidental Programmer Large Scale systems • Ease of use • Syntax cleanup

Language Updates Incidental Programmer Large Scale systems • Ease of use • Syntax cleanup • Program Correctness • Expressiveness • Interoperability (C) 2011 Alisdair Meredith Performance • Efficiency • Concurrency 9

Ease of use Declarations • auto • alias templates • raw string literals •

Ease of use Declarations • auto • alias templates • raw string literals • UTF 8 literals Initialization • delegating constructors • forwarding constructors • member initializers • list initialization (C) 2011 Alisdair Meredith Facilities • garbage collection • new for-loop • lambda expressions 10

Syntax cleanup: Extended syntax Simplified rules • • • . template typename right-angle-brackets reference

Syntax cleanup: Extended syntax Simplified rules • • • . template typename right-angle-brackets reference collapsing nested classes are members • extended SFINAE • Consistent initialization • default template parameters for function templates • sizeof (non-static) data members • linkage for local templates (C) 2011 Alisdair Meredith 11

Correctness: � � � explicit override ‘keyword’ nullptr strong enum forwarding constructors ('strong' typedef)

Correctness: � � � explicit override ‘keyword’ nullptr strong enum forwarding constructors ('strong' typedef) static_assert explicit conversion functions conditionally supported behavior -> more diagnosable errors deleted functions detect array-new overflow detect narrowing conversions (with new syntax) noexcept destructors (C) 2011 Alisdair Meredith 12

Expressiveness: New data types long char 16_t char 32_t extended integral types decltype auto

Expressiveness: New data types long char 16_t char 32_t extended integral types decltype auto function declarations extended friends extern template variadic templates variadic macros _Pragma move semantics perfect forwarding defaulted functions user defined literals initializer lists attributes trivial types fixed-base for enums forward declare enums enum class (C) 2011 Alisdair Meredith 13

Interoperability long Unicode char types Standard layout types Alignment specifiers C 99 preprocessor (C)

Interoperability long Unicode char types Standard layout types Alignment specifiers C 99 preprocessor (C) 2011 Alisdair Meredith 14

Efficiency Serial • • • rvalue references constexpr trivial types noexcept final virtual functions

Efficiency Serial • • • rvalue references constexpr trivial types noexcept final virtual functions • alignment control Concurrent • memory model • thread local storage • atomic operations (C) 2011 Alisdair Meredith 15

Miscellaneous � � � � � inline namespaces exception cloning native support for type

Miscellaneous � � � � � inline namespaces exception cloning native support for type traits __func__ and updated assert macro implicit move constructor implicit move-assignment operator reference qualifiers anonymous namespace has internal linkage concatenate string literals of different type (C) 2011 Alisdair Meredith 16

Where can we get it? � Most modern compilers implement a subset � static_assert

Where can we get it? � Most modern compilers implement a subset � static_assert � auto � decltype � rvalue references � lambda � � gcc 4. 6 has widest support Clang getting good coverage if you want to build your own (C) 2011 Alisdair Meredith 17