Download - C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing
![Page 1: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/1.jpg)
C++ 2011Highlights from the New International Standard
1
Monday, September 19, 2011
![Page 2: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/2.jpg)
Intro
• Who am I
• Who are you?
• Why We’re Here
2
Monday, September 19, 2011
![Page 3: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/3.jpg)
C++11 Goals
• Make C++ a better language for systems
programming
• Make C++ a better language for writing libraries
• Make C++ more teachable and learnable
• Maintain backward compatibility
3
Monday, September 19, 2011
![Page 4: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/4.jpg)
C++11 At a Glance
• General Core Language Features
concurrency, move semantics, auto, range-based for, lambdas…
• Library Features
containers, regular expressions, smart pointers, new algorithms…
• Features for writing classes
constructor delegation, override/final, =default/=delete…
• Crazy Template Stuff
Variadic templates, template aliases, decltype, perfect forwarding, …
4
Monday, September 19, 2011
![Page 5: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/5.jpg)
Ponies for Everybody!Big wins from little features
5
Monday, September 19, 2011
![Page 6: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/6.jpg)
Type Deduction
6
void print_3x(vector<float> const& v){ for ( vector<float>::const_iterator p = v.begin(); p != v.end(); p++ ) { std::cout << *p * 3 << " "; }}
Monday, September 19, 2011
![Page 7: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/7.jpg)
Type Deduction
6
void print_3x(vector<float> const& v){ for ( vector<float>::const_iterator p = v.begin(); p != v.end(); p++ ) { std::cout << *p * 3 << " "; }}
Monday, September 19, 2011
![Page 8: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/8.jpg)
Type Deduction
7
void print_3x(vector<float> const& v){ for ( auto p = v.begin(); p != v.end(); p++ ) { std::cout << *p * 3 << " "; }}
Monday, September 19, 2011
![Page 9: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/9.jpg)
Type Deduction
8
void print_3x(vector<float> const& v){ for ( auto p = v.begin(); p != v.end(); p++ ) { std::cout << *p * 3 << " "; }}
Monday, September 19, 2011
![Page 10: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/10.jpg)
Type Deduction
9
auto a = 3; intconst auto b = 3.14; const doubleauto const& c = 42; int const&
auto d = "foobar"; char const*auto& e = "baz" char const(&)[4]
extern std::list<Foo> l;auto p = l.begin(); std::list<Foo>::iteratorauto& x = l.front(); std::list<Foo>::value_type&
auto& y = any-expression-here;
Monday, September 19, 2011
![Page 11: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/11.jpg)
Type Deduction
10
void print_3x(vector<float> const& v){ for ( auto p = v.begin(); p != v.end(); p++ ) { std::cout << *p * 3 << " "; }}
Monday, September 19, 2011
![Page 12: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/12.jpg)
Range-based for loop
11
void print_3x(vector<float> const& v){ for ( auto p = v.begin(); p != v.end(); p++ ) { std::cout << *p * 3 << " "; }}
Monday, September 19, 2011
![Page 13: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/13.jpg)
Range-based for loop
12
void print_3x(vector<float> const& v){ for ( float a: v ) { std::cout << a * 3 << " "; }}
Monday, September 19, 2011
![Page 14: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/14.jpg)
Range-based for loop
12
void print_3x(vector<float> const& v){ for ( float a: v ) { std::cout << a * 3 << " "; }}
Range
Monday, September 19, 2011
![Page 15: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/15.jpg)
Range-based for loop
12
void print_3x(vector<float> const& v){ for ( float a: v ) { std::cout << a * 3 << " "; }}
Loop variable Range
Monday, September 19, 2011
![Page 16: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/16.jpg)
auto in C++11Range-based for loop
13
void print_3x(vector<float> const& v){ for ( auto a: v ) { std::cout << a * 3 << " "; }}
Monday, September 19, 2011
![Page 17: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/17.jpg)
Range-based for loop
14
template <class Range>void print_3x(Range const& v){ for ( typename Range::value_type a: v ) { std::cout << a * 3 << " "; }}
Monday, September 19, 2011
![Page 18: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/18.jpg)
auto in C++11Range-based for loop
15
template <class Range>void print_3x(Range const& v){ for ( auto a: v ) { std::cout << a * 3 << " "; }}
Monday, September 19, 2011
![Page 19: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/19.jpg)
auto in C++11Range-based for loop
16
void inplace_3x(vector<float>& v){ for ( float& a: v ) { a *= 3; }}
Monday, September 19, 2011
![Page 20: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/20.jpg)
Ranges Everywhere
17
int rng[3] = { 42, 314, 77 };for( int var: rng ){ ...}
Monday, September 19, 2011
![Page 21: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/21.jpg)
Ranges Everywhere
18
std::pair<Iter,Iter> rng = … ;for( int var: rng ){ ...}
Monday, September 19, 2011
![Page 22: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/22.jpg)
Ranges Everywhere
19
YourType rng;for( int var: rng ){ ...}
Monday, September 19, 2011
![Page 23: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/23.jpg)
Range-based for loop
20
void print_3x(vector<float> const& v){ BOOST_FOREACH( float a, v ) { std::cout << a * 3 << " "; }}
C++98
Monday, September 19, 2011
![Page 24: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/24.jpg)
Range-based for loop
20
void print_3x(vector<float> const& v){ BOOST_FOREACH( float a, v ) { std::cout << a * 3 << " "; }}
“ ”C++98
Monday, September 19, 2011
![Page 25: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/25.jpg)
Range-based for loop
20
void print_3x(vector<float> const& v){ BOOST_FOREACH( float a, v ) { std::cout << a * 3 << " "; }}
“ ”C++98
See your friendly neighborhood Boost C++ Libraries for details
Monday, September 19, 2011
![Page 26: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/26.jpg)
Using an Algorithm
21
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(), );}
Monday, September 19, 2011
![Page 27: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/27.jpg)
Using an Algorithm
21
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(), );}
Monday, September 19, 2011
![Page 28: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/28.jpg)
Using an Algorithm
21
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(), );}
Monday, September 19, 2011
![Page 29: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/29.jpg)
Using an Algorithm
21
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(), );}
static void print_3x_element(float a){ std::cout << a * 3 << " ";}
Monday, September 19, 2011
![Page 30: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/30.jpg)
Using an Algorithm
21
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(), );}
static void print_3x_element(float a){ std::cout << a * 3 << " ";}
print_3x_element
Monday, September 19, 2011
![Page 31: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/31.jpg)
Using an Algorithm
21
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(), );}
static void print_3x_element(float a){ std::cout << a * 3 << " ";}
print_3x_element
Monday, September 19, 2011
![Page 32: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/32.jpg)
Lambda Expressions
22
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(),
);}
Monday, September 19, 2011
![Page 33: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/33.jpg)
Lambda Expressions
22
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(),
);}
“Lambda expression”
[](float a) { std::cout << a * 3 << " "; }
Monday, September 19, 2011
![Page 34: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/34.jpg)
Lambda Expressions
23
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(),
[](float a) { std::cout << a * 3 << " "; } );}
Monday, September 19, 2011
![Page 35: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/35.jpg)
Lambda Expressions
23
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(),
[](float a) { std::cout << a * 3 << " "; } );}
introducer
Monday, September 19, 2011
![Page 36: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/36.jpg)
What It Is
24
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(),
[](float a) { std::cout << a * 3 << " "; } );}
Monday, September 19, 2011
![Page 37: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/37.jpg)
What It Is
24
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(),
[](float a) { std::cout << a * 3 << " "; } );}
struct __lambda143{ inline void operator()(float a) const { std::cout << a * 3 << " "; }};
anonymous class
Monday, September 19, 2011
![Page 38: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/38.jpg)
What It Is
24
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(),
[](float a) { std::cout << a * 3 << " "; } );}
struct __lambda143{ inline void operator()(float a) const { std::cout << a * 3 << " "; }};
anonymous class
Monday, September 19, 2011
![Page 39: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/39.jpg)
What It Is
24
void print_3x(vector<float> const& v){ std::for_each( v.begin(), v.end(),
[](float a) { std::cout << a * 3 << " "; } );}
struct __lambda143{ inline void operator()(float a) const { std::cout << a * 3 << " "; }};
__lambda143()
anonymous class
“closure” instance
Monday, September 19, 2011
![Page 40: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/40.jpg)
std::vector<std::pair<int, std::string>> x;
Closing Angle Brackets
25
Monday, September 19, 2011
![Page 41: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/41.jpg)
std::vector<std::pair<int, std::string>> x;
Closing Angle Brackets
25
Error in C++98: >> tokenized as right-shift
Dummy
Monday, September 19, 2011
![Page 42: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/42.jpg)
std::vector<std::pair<int, std::string>> x;
Closing Angle Brackets
25
OK in C++11
Dummy
Monday, September 19, 2011
![Page 43: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/43.jpg)
Move SemanticsA Really Cheap Lunch
26
Monday, September 19, 2011
![Page 44: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/44.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
Monday, September 19, 2011
![Page 45: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/45.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
Monday, September 19, 2011
![Page 46: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/46.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
Monday, September 19, 2011
![Page 47: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/47.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A
Monday, September 19, 2011
![Page 48: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/48.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A B
Monday, September 19, 2011
![Page 49: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/49.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A B C
Monday, September 19, 2011
![Page 50: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/50.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A B C D
Monday, September 19, 2011
![Page 51: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/51.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A B C D
Monday, September 19, 2011
![Page 52: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/52.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A B C D
A
Monday, September 19, 2011
![Page 53: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/53.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A B C D
A B
Monday, September 19, 2011
![Page 54: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/54.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A B C D
A B C
Monday, September 19, 2011
![Page 55: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/55.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
27
• A B C D
A B C D
Monday, September 19, 2011
![Page 56: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/56.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
28
• A B C D
A B C D
Monday, September 19, 2011
![Page 57: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/57.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
28
•
A B C D
Monday, September 19, 2011
![Page 58: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/58.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
28
• A B C D
Monday, September 19, 2011
![Page 59: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/59.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
28
• A B C D E
Monday, September 19, 2011
![Page 60: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/60.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
28
• A B C D E
Monday, September 19, 2011
![Page 61: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/61.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Copy Fatigue?
28
• A B C D E
Expensive copies are made just
before destroying the source
object
Monday, September 19, 2011
![Page 62: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/62.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
29
• B C DA
Monday, September 19, 2011
![Page 63: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/63.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
29
• B C D
A
Monday, September 19, 2011
![Page 64: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/64.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
29
•
B
C D
A
Monday, September 19, 2011
![Page 65: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/65.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
29
•
B C
D
A
Monday, September 19, 2011
![Page 66: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/66.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
29
•
B C DA
Monday, September 19, 2011
![Page 67: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/67.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
29
•
B C DA
Monday, September 19, 2011
![Page 68: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/68.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
30
•
A B C D
Monday, September 19, 2011
![Page 69: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/69.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
30
• A B C D
Monday, September 19, 2011
![Page 70: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/70.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
30
• A B C D E
Monday, September 19, 2011
![Page 71: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/71.jpg)
typedef set<string> record;typedef vector<record> database;
database load_db(string filename);database db = load_db("huge.db");
db.push_back( create_record() );
Try Moving Instead!
30
• A B C D E
Monday, September 19, 2011
![Page 72: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/72.jpg)
Move Mini-HOWTOMove-enabling an existing class
31
Monday, September 19, 2011
![Page 73: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/73.jpg)
X
Move-Enabling
32
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• X
Monday, September 19, 2011
![Page 74: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/74.jpg)
X
Move-Enabling
32
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• X
Monday, September 19, 2011
![Page 75: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/75.jpg)
X
Move-Enabling
32
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• X
Monday, September 19, 2011
![Page 76: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/76.jpg)
X
Move-Enabling
32
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• X
Monday, September 19, 2011
![Page 77: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/77.jpg)
X
Move-Enabling
32
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• X
Monday, September 19, 2011
![Page 78: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/78.jpg)
X
Move-Enabling
32
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• X
•
Monday, September 19, 2011
![Page 79: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/79.jpg)
Y
Move-Enabling
33
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• Y
• Z
Monday, September 19, 2011
![Page 80: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/80.jpg)
Y
Move-Enabling
33
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• Y
• Z
Monday, September 19, 2011
![Page 81: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/81.jpg)
Y
Move-Enabling
33
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• Y
• Z
Monday, September 19, 2011
![Page 82: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/82.jpg)
Y
Move-Enabling
33
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• Y
•
Monday, September 19, 2011
![Page 83: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/83.jpg)
Y
Move-Enabling
33
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• Y
•
Monday, September 19, 2011
![Page 84: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/84.jpg)
Y
Move-Enabling
33
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• Y
•
Monday, September 19, 2011
![Page 85: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/85.jpg)
Y
Move-Enabling
33
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• Y
•
Monday, September 19, 2011
![Page 86: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/86.jpg)
Y
Move-Enabling
33
struct Owner { Owner(const Owner& src) : p(src.p ? new Resource(*src.p) : 0) {}
Owner& operator=(const Owner& src) { if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
~Owner() { delete p; }private: Resource* p;};
• Y
•
Monday, September 19, 2011
![Page 87: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/87.jpg)
New Move Operations
{ if (this == &src) return *this; delete p; p = 0; if (src.p) p = new Resource(*src.p); return *this; }
34
struct Owner { Owner(const Owner& src)
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(const Owner& src)
: p(src.p ? new Resource(*src.p) : 0) {}
Monday, September 19, 2011
![Page 88: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/88.jpg)
New Move Operations
34
struct Owner { Owner(const Owner& src)
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(const Owner& src)
Monday, September 19, 2011
![Page 89: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/89.jpg)
New Move Operations
34
struct Owner { Owner(const Owner& src)
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(const Owner& src)
Monday, September 19, 2011
![Page 90: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/90.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
X• X
Monday, September 19, 2011
![Page 91: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/91.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
X• X
Monday, September 19, 2011
![Page 92: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/92.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
Owner(Owner&& src) : p(src.p) { src.p = 0; }
X• X
Monday, September 19, 2011
![Page 93: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/93.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
Owner(Owner&& src) : p(src.p) { src.p = 0; }
X• X
rvalue reference
Monday, September 19, 2011
![Page 94: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/94.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
Owner(Owner&& src) : p(src.p) { src.p = 0; }
X• X
rvalue reference
Monday, September 19, 2011
![Page 95: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/95.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
Owner(Owner&& src) : p(src.p) { src.p = 0; }
X• X
Monday, September 19, 2011
![Page 96: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/96.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
Owner(Owner&& src) : p(src.p) { src.p = 0; }
•
X• X
Monday, September 19, 2011
![Page 97: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/97.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
Owner(Owner&& src) : p(src.p) { src.p = 0; }
•
X• X
Monday, September 19, 2011
![Page 98: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/98.jpg)
Move Constructor
35
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
~Owner() { delete p; }private: Resource* p;};
Owner(Owner&& src) : p(src.p) { src.p = 0; }
•
X• X
•
Monday, September 19, 2011
![Page 99: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/99.jpg)
Move Assignment
36
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
Owner(Owner&& src) : p(src.p) { src.p = 0; }
~Owner() { delete p; }private: Resource* p;};
Y•
• Z
Monday, September 19, 2011
![Page 100: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/100.jpg)
Move Assignment
36
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
Owner(Owner&& src) : p(src.p) { src.p = 0; }
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(Owner&& src) { if (this == &src) return *this; delete p; p = src.p; src.p = 0; return *this; }
Y•
• Z
Monday, September 19, 2011
![Page 101: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/101.jpg)
Move Assignment
36
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
Owner(Owner&& src) : p(src.p) { src.p = 0; }
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(Owner&& src) { if (this == &src) return *this; delete p; p = src.p; src.p = 0; return *this; }
Y•
• Z
Monday, September 19, 2011
![Page 102: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/102.jpg)
Move Assignment
36
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
Owner(Owner&& src) : p(src.p) { src.p = 0; }
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(Owner&& src) { if (this == &src) return *this; delete p; p = src.p; src.p = 0; return *this; }
Y•
• Z
Monday, September 19, 2011
![Page 103: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/103.jpg)
Move Assignment
36
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
Owner(Owner&& src) : p(src.p) { src.p = 0; }
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(Owner&& src) { if (this == &src) return *this; delete p; p = src.p; src.p = 0; return *this; }
Y•
•
Monday, September 19, 2011
![Page 104: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/104.jpg)
Move Assignment
36
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
Owner(Owner&& src) : p(src.p) { src.p = 0; }
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(Owner&& src) { if (this == &src) return *this; delete p; p = src.p; src.p = 0; return *this; }
Y•
•
Monday, September 19, 2011
![Page 105: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/105.jpg)
Move Assignment
36
struct Owner { Owner(const Owner& src); Owner& operator=(const Owner& src);
Owner(Owner&& src) : p(src.p) { src.p = 0; }
~Owner() { delete p; }private: Resource* p;};
Owner& operator=(Owner&& src) { if (this == &src) return *this; delete p; p = src.p; src.p = 0; return *this; }
Y
•
•
Monday, September 19, 2011
![Page 106: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/106.jpg)
Move Semantics
• Automatically accelerates existing code!
• Applied throughout standard library
• Many move-only types in library
• Launches a new era of value semantics
37
Monday, September 19, 2011
![Page 107: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/107.jpg)
Containers
• Move semantics
• Hash containers
• forward_list
• array
• tuple
• Emplace
• Allocators
38
Monday, September 19, 2011
![Page 108: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/108.jpg)
Other Useful Libraries
• regex:
• Algorithms
• function / bind
39
Monday, September 19, 2011
![Page 109: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/109.jpg)
Smart Pointers
• unique_ptr
• shared_ptr
40
Monday, September 19, 2011
![Page 110: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/110.jpg)
Classes and OOP
• member initializers
• explict conversion
• override and final
• delegating and inheriting constructors
• defaulted and deleted functions
41
Monday, September 19, 2011
![Page 111: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/111.jpg)
Concurrency
• async, futures, promise
• locks, mutexes and condition variables
• exception propagation
• atomics
42
Monday, September 19, 2011
![Page 112: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/112.jpg)
Templates
• Variadics
• static_assert
• local classes as template arguments
• extern templates
• Template aliases
43
Monday, September 19, 2011
![Page 113: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/113.jpg)
Metaprogramming
• constexpr
• Template aliases
• User-defined literals w/variadic templates
• Type traits and extended SFINAE
44
Monday, September 19, 2011
![Page 114: C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing](https://reader033.vdocuments.site/reader033/viewer/2022060108/554f7084b4c905c8088b5540/html5/thumbnails/114.jpg)
What’s Next?
• Modules
• Concepts
• Pythy Syntax:
• []min(x, y) { return x < y ? x : y }
45
Monday, September 19, 2011