EMBARCADEROEMBARCADERO TECHNOLOGIESTECHNOLOGIESC++11 and Compiler Update
John “JT” Thomas
Sr. Director Application DeveloperProducts

EMBARCADERO TECHNOLOGIES

About this Session• A Brief History• Features of C++11 you should be using now• Questions

2

EMBARCADERO TECHNOLOGIES

Bjarne Stroustrup• C with Objects (1979)– Modeled OO after Simula andAda• But syntax and RTL based on C

– Classes– Inheritance– Inlining– Default arguments– Type checking– CFront compiler

EMBARCADERO TECHNOLOGIESA Brief History of C++

EMBARCADERO TECHNOLOGIESEMBARCADERO TECHNOLOGIESEMBARCADERO TECHNOLOGIESC++11 – A new Standard
Language•••••••••••••••••

Rvalue references and move constructors
constexpr - Generalized constant expressions
Core language usability enhancements
Initializer lists
Uniform initialization
Type inference
Range-based for-loop
Lambda functions and expressions
Alternative function syntax
Object construction improvement
Explicit overrides and final
Null pointer constant
Strongly typed enumerations
Right angle bracket
Explicit conversion operators
Alias templates
Unrestricted unions

Library••••••••••••••••••••

Variadic templates
New string literals
User-defined literals
Multithreading memory modelThread-local storage
Explicitly defaulted and deleted special memberfunctions
Type long long int
Static assertions
Allow sizeof to work on members of classes
without an explicit object
Control and query object alignment
Allow garbage collected implementations
Threading facilities
Tuple types
Hash tables
Regular expressions
General-purpose smart pointers
Extensible random number facility
Wrapper reference
Polymorphic wrappers for function objects
Type traits for metaprogrammingEMBARCADERO TECHNOLOGIESEMBARCADERO TECHNOLOGIES

auto keyword• Type inference• auto asks the compiler
to deduce the type
• Helps with readabilityof code especially withtemplate containeriterators
9• auto i = 9; //int• auto f = 3.14f; //float• auto f = new foo(); //foo*EMBARCADERO TECHNOLOGIES

ranged for loop
• a for_each concept to loop
through standard containers• Any type with a begin() and end()• for (auto i : map)
– access I by value• Use auto& I for ref to modify• Use auto const & I for ref to readyonly10EMBARCADERO TECHNOLOGIES

Smart pointers• C++ version of ARC• auto_ptr is deprecated• 3 new smart pointers inC++11– unique_ptr, shared_ptr, andweak_ptr•unique_ptr––•

shared_ptr–•

Ownership of memory is shared (referencecounted)

weak_ptr––

11

Ownership of memory does not have to beshared
Can be transferred to another unique_ptr witha move constructor

Reference to an object managed by shared_ptr
but does not contribute to the ref count
Used to avoid reference cycle

EMBARCADERO TECHNOLOGIES

Move semantics• Modify rvaluereferences• Specified by &&• Implemented as a moveconstructor and moveassignment operator
12

EMBARCADERO TECHNOLOGIESUniform initialization syntax• C++ have a long history
with sporadic
compatibility with C– Thus, there are several
ways to initiate avariable• STL containers required
dynamic initilization
13– i.e. push_back

EMBARCADERO TECHNOLOGIESOverride and final• Deaks with typicalinheritance issues/mistakes– Differing signatures
accidently resulting in a nonoverride• Override indicates amethod is supposed tooverried a virtual method inits base14

• final indicates a method
can no longer beoverridden

EMBARCADERO TECHNOLOGIES

nullptr• Zero (integer) used tobe value of null pointers– Could result in implicit
type conversion• nullptr is of typestd::nullptr_t that
represents a nullpointer literal15• Implicit conversion from– nullptr to null pointervalue of any pointer type

EMBARCADERO TECHNOLOGIES

lambda expressions• New syntax for defining
anonymous functions• Can be used to define
closures to capture
variables16• [capture-list] (params){body;}• [capture-list] (params)->ret {body;}• [capture-list] (params)
mutable exception
attributed -> ret {body;}

EMBARCADEROEMBARCADERO TECHNOLOGIESTECHNOLOGIESC++ Compiler Update

17

EMBARCADERO TECHNOLOGIES

Active projects• Move to CLANG 3.3– Full C++ compliance– futures/async• Support C++11 on all platforms– Win32 CLANG based toolchain• Current version owners will be invited to participate
in a beta when it is released
18

EMBARCADEROEMBARCADERO TECHNOLOGIESTECHNOLOGIESQuestions?

19