Professional Documents
Culture Documents
2-661
Updates: ISO C++, VC++ roadmap
C++98 C++03 C++11 C++14 C++17
(major) (TC, bug fixes only) (major) (minor) (major)
Uniform init & C99 variable decls C++14 auto function C++14 generalized
User-defined literals thread_local
initializer_lists C99 _Bool return type deduction constexpr
C++14 libs: cbegin/ C99 designated C++TS? async/await C++14 libs: std:: user- constexpr (except C++TS concepts
greater<>/make_unique initializers (partial) defined literals ctors, literal types) lite
High confidence
Med confidence
Uniform init & C99 variable decls C++14 auto function C++14 generalized
User-defined literals thread_local
initializer_lists C99 _Bool return type deduction constexpr
C++14 libs: cbegin/ C99 designated C++TS? async/await C++14 libs: std:: user- constexpr (except C++TS concepts
greater<>/make_unique initializers (partial) defined literals ctors, literal types) lite
Modern C++: What you need to know
▪
C++
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪ ▪
▪
Then: C++98 code
circle* p = new circle( 42 );
vector<shape*> v = load_shapes();
for( vector<shape*>::iteratori = v.begin(); i != v.end(); ++i ) {
if( *i && **i == *p )
cout << **i << “ is a match\n”;
}
// … later, possibly elsewhere …
for( vector<shape*>::iterator i = v.begin();
i != v.end(); ++i ) {
delete *i;
}
delete p;
T* → shared_ptr<T>
auto type deduction
new → make_unique
Then: C++98 code Now: Modern C++ or make_shared
automatic return
type deduction
set<widget> load_huge_data() { Matrix operator+(
set<widget> ret; const Matrix&,
// … load data and populate ret … const Matrix&
return ret; );
} m4 = m1+m2+m3;
widgets = load_huge_data();
efficient, no deep copies
efficient, no deep copy
if (auto x = …) {
…
}
int do_work() {
auto x = …;
}
class widget {
gadget g;
};
class widget { void f() { lifetime automatically
“all types are widget w;
private: tied to enclosing scope
IDisposable” :::
gadget g; constructs w, including
lifetime automatically w.draw(); the w.g gadget member
public: tied to enclosing object
void draw(); :::
no leak, exception safe
}; } automatic destruction
and deallocation for w
and w.g
automatic propagation,
as if “widget.dispose()
{ g.dispose(); }” automatic exception
safety, as if “finally {
w.g.dispose();
w.dispose(); }”
▪
▪
▪
▪
▪
▪
▪
▪
{
widget a;
gadget b;
vector<int> c;
:::
}
▪
▪
▪
▪
▪
▪
▪
▪
▪
stack heap heap
ptr
ptr
ptr
stack heap heap stack heap
ptr
ptr
ptr
stack heap heap stack heap stack
ptr
ptr
ptr
▪
▪
▪
▪
▪
▪
array, vector ▪
▪
list, tree, graph, … ▪
▪
You can see it trying to
prefetch, scrambling ▪
madly to stay ahead and
keep the pipeline full…!
▪
▪
∞
▪
▪
▪ http://gameprogrammingpatterns.com/data-locality.html
Original code
class GameEntity {
AIComponent* ai_;
PhysicsComponent* physics_;
RenderComponent* render_;
:::
};
vector<GameEntity> entities;
data
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪
sequence test
5000
4500
4000
3500
3000
Seconds 2500
vector
2000 list
1500
preallocated list
1000
500
0
1 2 3 4 5
*100,000 elements
▪
▪
▪
Free store info
▪
▪
▪
data
▪
▪
▪
▪
▪
▪
▪ This completely dominates
▪
▪
▪
▪ ▪
▪ ▪
▪ ▪
▪
4500
4000
3500
3000
vector
seconds
2500
list
2000
list (preallocate)
1500 map
1000
500
0
1 2 3 4 5
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪ vector< unique_ptr<shape> > shapes;
▪
▪ vector< shape* > shapes;
▪
for/while/do →
std:: algorithms
Then Now [&] lambda functions
for( auto i = v.begin(); i != v.end(); ++i ) { for_each( begin(v), end(v), []( string& s ) {
::: :::
for_each to visit each element
::: :::
::: arbitrary length lambda :::
bodies, just put the loop
} } );
body inside the lambda
find_if to find a match
https://parallelstl.codeplex.com
What you need to know next
▪ 2014-15: Multiple C++14 complete implementations
▪
▪
▪
C++’s biggest conference ever
▪ Sold out, 18 countries, 23 states
▪ Global live webcast: Over 20,000 viewers
▪ Global on demand: Over 600,000 viewers
And we did it again!
▪ Sold out, 10 countries, 26 states
▪ Global live webcast: Over 20,000 viewers
▪ Global on demand: Over 1,000,000 viewers
▪ CppCon 2014 estimate: 150+ full- and half-length talks
▪ Invited talks/panels and domain experts
▪ + Lightning talks
▪ + Evening events and “unconference” time
Call for Submissions open now:
& more …