SlideShare una empresa de Scribd logo
1 de 114
Descargar para leer sin conexión
C++ 2011
                             Highlights from the New International Standard




                                                   1
Monday, September 19, 2011
Intro

                   •         Who am I


                   •         Who are you?


                   •         Why We’re Here



                                              2
Monday, September 19, 2011
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
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
Ponies for Everybody!
                             Big wins from little features




                                           5
Monday, September 19, 2011
Type Deduction

                 void print_3x(vector<float> const& v)
                 {
                     for ( vector<float>::const_iterator p = v.begin();
                           p != v.end(); p++ )
                     {
                         std::cout << *p * 3 << " ";
                     }
                 }




                                             6
Monday, September 19, 2011
Type Deduction

                 void print_3x(vector<float> const& v)
                 {
                     for ( vector<float>::const_iterator p = v.begin();
                           p != v.end(); p++ )
                     {
                         std::cout << *p * 3 << " ";
                     }
                 }




                                             6
Monday, September 19, 2011
Type Deduction

                 void print_3x(vector<float> const& v)
                 {
                     for ( auto p = v.begin();
                           p != v.end(); p++ )
                     {
                         std::cout << *p * 3 << " ";
                     }
                 }




                                             7
Monday, September 19, 2011
Type Deduction

                 void print_3x(vector<float> const& v)
                 {
                     for ( auto p = v.begin(); p != v.end(); p++ )
                     {
                         std::cout << *p * 3 << " ";
                     }
                 }




                                             8
Monday, September 19, 2011
Type Deduction
              auto                 a = 3;               int
              const auto           b = 3.14;            const double
              auto 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>::iterator
              auto& x = l.front();                      std::list<Foo>::value_type&


              auto& y =          any-expression-here;


                                                    9
Monday, September 19, 2011
Type Deduction

                 void print_3x(vector<float> const& v)
                 {
                     for ( auto p = v.begin(); p != v.end(); p++ )
                     {
                         std::cout << *p * 3 << " ";
                     }
                 }




                                             10
Monday, September 19, 2011
Range-based for loop

                 void print_3x(vector<float> const& v)
                 {
                     for ( auto p = v.begin(); p != v.end(); p++ )
                     {
                         std::cout << *p * 3 << " ";
                     }
                 }




                                             11
Monday, September 19, 2011
Range-based for loop

                 void print_3x(vector<float> const& v)
                 {
                     for ( float a: v )
                     {
                         std::cout << a * 3 << " ";
                     }
                 }




                                             12
Monday, September 19, 2011
Range-based for loop

                 void print_3x(vector<float> const& v)
                                           Range
                 {
                     for ( float a: v )
                     {
                         std::cout << a * 3 << " ";
                     }
                 }




                                             12
Monday, September 19, 2011
Range-based for loop

                 void print_3x(vector<float> const& v)
                    Loop variable          Range
                 {
                     for ( float a: v )
                     {
                          std::cout << a * 3 << " ";
                     }
                 }




                                             12
Monday, September 19, 2011
Range-based for loop
                        auto in C++11


                 void print_3x(vector<float> const& v)
                 {
                     for ( auto a: v )
                     {
                         std::cout << a * 3 << " ";
                     }
                 }




                                             13
Monday, September 19, 2011
Range-based for loop

                 template <class Range>
                 void print_3x(Range const& v)
                 {
                     for ( typename Range::value_type a: v )
                     {
                         std::cout << a * 3 << " ";
                     }
                 }




                                             14
Monday, September 19, 2011
Range-based for loop
                        auto in C++11

                 template <class Range>
                 void print_3x(Range const& v)
                 {
                     for ( auto a: v )
                     {
                         std::cout << a * 3 << " ";
                     }
                 }




                                            15
Monday, September 19, 2011
Range-based for loop
                        auto in C++11


                 void inplace_3x(vector<float>& v)
                 {
                     for ( float& a: v )
                     {
                         a *= 3;
                     }
                 }




                                             16
Monday, September 19, 2011
Ranges Everywhere
                             int rng[3] = { 42, 314, 77 };
                             for( int var: rng )
                             {
                                 ...
                             }




                                            17
Monday, September 19, 2011
Ranges Everywhere
                             std::pair<Iter,Iter> rng = … ;
                             for( int var: rng )
                             {
                                 ...
                             }




                                            18
Monday, September 19, 2011
Ranges Everywhere
                             YourType rng;
                             for( int var: rng )
                             {
                                 ...
                             }




                                            19
Monday, September 19, 2011
98
     ++Range-based for loop
    C

                 void print_3x(vector<float> const& v)
                 {
                     BOOST_FOREACH( float a, v )
                     {
                         std::cout << a * 3 << " ";
                     }
                 }




                                             20
Monday, September 19, 2011
98
     ++Range-based“for”loop
    C

                 void print_3x(vector<float> const& v)
                 {
                     BOOST_FOREACH( float a, v )
                     {
                         std::cout << a * 3 << " ";
                     }
                 }




                                             20
Monday, September 19, 2011
98
     ++Range-based“for”loop
    C

                 void print_3x(vector<float> const& v)
                 {
                     BOOST_FOREACH( float a, v )
                     {
                         std::cout << a * 3 << " ";
                     }
                 }

                             See your friendly neighborhood
                             Boost C++ Libraries for details


                                             20
Monday, September 19, 2011
Using an Algorithm


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),             );
                 }




                                             21
Monday, September 19, 2011
Using an Algorithm


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),             );
                 }




                                             21
Monday, September 19, 2011
Using an Algorithm


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),             );
                 }




                                             21
Monday, September 19, 2011
Using an Algorithm
                 static void print_3x_element(float a)
                 {
                     std::cout << a * 3 << " ";
                 }


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),             );
                 }




                                             21
Monday, September 19, 2011
Using an Algorithm
                 static void print_3x_element(float a)
                 {
                     std::cout << a * 3 << " ";
                 }


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(), print_3x_element);
                 }




                                             21
Monday, September 19, 2011
Using an Algorithm
                 static void print_3x_element(float a)
                 {
                     std::cout << a * 3 << " ";
                 }


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(), print_3x_element);
                 }




                                             21
Monday, September 19, 2011
Lambda Expressions


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),
                                                         );
                 }




                                             22
Monday, September 19, 2011
Lambda Expressions


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),
                              [](float a) { std::cout << a * 3 << " "; } );
                 }

                                          “Lambda expression”


                                                  22
Monday, September 19, 2011
Lambda Expressions


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),
                         [](float a) { std::cout << a * 3 << " "; } );
                 }




                                             23
Monday, September 19, 2011
Lambda Expressions


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),
                         [](float a) { std::cout << a * 3 << " "; } );
                 }

              introducer


                                             23
Monday, September 19, 2011
What It Is


                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),
                         [](float a) { std::cout << a * 3 << " "; } );
                 }




                                             24
Monday, September 19, 2011
anonymous class
                                 What It Is
                 struct __lambda143
                 {
                      inline void operator()(float a) const
                      { std::cout << a * 3 << " "; }
                 };

                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),
                         [](float a) { std::cout << a * 3 << " "; } );
                 }




                                             24
Monday, September 19, 2011
anonymous class
                                 What It Is
                 struct __lambda143
                 {
                      inline void operator()(float a) const
                      { std::cout << a * 3 << " "; }
                 };

                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),
                         [](float a) { std::cout << a * 3 << " "; } );
                 }




                                             24
Monday, September 19, 2011
anonymous class
                                 What It Is
                 struct __lambda143
                 {
                      inline void operator()(float a) const
                      { std::cout << a * 3 << " "; }
                 };

                 void print_3x(vector<float> const& v)
                 {
                     std::for_each(
                         v.begin(), v.end(),
                         __lambda143()
                         [](float a) { std::cout << a * 3 << " "; } );
                 }
                                       “closure” instance



                                             24
Monday, September 19, 2011
Closing Angle Brackets


                             std::vector<std::pair<int, std::string>> x;




                                                  25
Monday, September 19, 2011
Closing Angle Brackets

                                                 Error in C++98: >>
                                               tokenized as right-shift


                             std::vector<std::pair<int, std::string>> x;




                                                   25
Monday, September 19, 2011
Closing Angle Brackets


                             std::vector<std::pair<int, std::string>> x;


                                                       OK in C++11




                                                  25
Monday, September 19, 2011
Move Semantics
                                A Really Cheap Lunch




                                         26
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );




                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );




                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );




                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A



                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B



                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C



                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D



                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D



                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D

                                    A

                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D

                                    A B

                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D

                                    A B C

                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D

                                    A B C D

                                              27
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D

                                    A B C D

                                              28
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •

                                    A B C D

                                              28
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D



                                              28
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D E



                                              28
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                             •      A B C D E



                                              28
Monday, September 19, 2011
Copy Fatigue?
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);    Expensive
                             database db = load_db("huge.db");
                                                                  copies are
                                                                   made just
                                                                    before
                             db.push_back( create_record() );     destroying
                                                                  the source
                                                                    object
                             •      A B C D E



                                              28
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •     A B C D



                                              29
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •         B C D

                                    A

                                              29
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •           C D

                                    A B

                                              29
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •              D

                                    A B C

                                              29
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •

                                    A B C D

                                              29
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •

                                    A B C D

                                              29
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •

                                    A B C D

                                              30
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •     A B C D



                                              30
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •     A B C D E



                                              30
Monday, September 19, 2011
Try Moving Instead!
                             typedef set<string> record;
                             typedef vector<record> database;

                             database load_db(string filename);
                             database db = load_db("huge.db");

                             db.push_back( create_record() );


                              •     A B C D E



                                              30
Monday, September 19, 2011
Move Mini-HOWTO
                             Move-enabling an existing class




                                           31
Monday, September 19, 2011
Move-Enabling
                 struct Owner {                                         •   X
                     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;
                 };

                                                     32
Monday, September 19, 2011
Move-Enabling
                 struct Owner {                                         •   X
                     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;
                 };

                                                     32
Monday, September 19, 2011
Move-Enabling
                 struct Owner {                                         •   X
                     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;
                 };

                                                     32
Monday, September 19, 2011
Move-Enabling
                 struct Owner {                                         •   X
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}             X
                             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;
                 };

                                                     32
Monday, September 19, 2011
Move-Enabling
                 struct Owner {                                         •   X
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}             X
                             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;
                 };

                                                     32
Monday, September 19, 2011
Move-Enabling
                 struct Owner {                                         •   X
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}         •   X
                             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;
                 };

                                                     32
Monday, September 19, 2011
Move-Enabling
                 struct Owner {
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}

                             Owner& operator=(const Owner& src) {
                                 if (this == &src) return *this;        •   Y
                                 delete p; p = 0;
                                 if (src.p) p = new Resource(*src.p);   •   Z
                                 return *this;
                             }

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     33
Monday, September 19, 2011
Move-Enabling
                 struct Owner {
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}

                             Owner& operator=(const Owner& src) {
                                 if (this == &src) return *this;        •   Y
                                 delete p; p = 0;
                                 if (src.p) p = new Resource(*src.p);   •   Z
                                 return *this;
                             }

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     33
Monday, September 19, 2011
Move-Enabling
                 struct Owner {
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}

                             Owner& operator=(const Owner& src) {
                                 if (this == &src) return *this;        •   Y
                                 delete p; p = 0;
                                 if (src.p) p = new Resource(*src.p);   •   Z
                                 return *this;
                             }

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     33
Monday, September 19, 2011
Move-Enabling
                 struct Owner {
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}

                             Owner& operator=(const Owner& src) {
                                 if (this == &src) return *this;        •   Y
                                 delete p; p = 0;
                                 if (src.p) p = new Resource(*src.p);   •
                                 return *this;
                             }

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     33
Monday, September 19, 2011
Move-Enabling
                 struct Owner {
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}

                             Owner& operator=(const Owner& src) {
                                 if (this == &src) return *this;        •   Y
                                 delete p; p = 0;
                                 if (src.p) p = new Resource(*src.p);   •
                                 return *this;
                             }

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     33
Monday, September 19, 2011
Move-Enabling
                 struct Owner {
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}

                             Owner& operator=(const Owner& src) {
                                 if (this == &src) return *this;        •   Y
                                 delete p; p = 0;
                                 if (src.p) p = new Resource(*src.p);   •
                                 return *this;
                             }

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     33
Monday, September 19, 2011
Move-Enabling
                 struct Owner {
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}

                             Owner& operator=(const Owner& src) {
                                 if (this == &src) return *this;        •   Y
                                 delete p; p = 0;
                                 if (src.p) p = new Resource(*src.p);   •   Y
                                 return *this;
                             }

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     33
Monday, September 19, 2011
Move-Enabling
                 struct Owner {
                     Owner(const Owner& src)
                       : p(src.p ? new Resource(*src.p) : 0) {}

                             Owner& operator=(const Owner& src) {
                                 if (this == &src) return *this;        •   Y
                                 delete p; p = 0;
                                 if (src.p) p = new Resource(*src.p);   •   Y
                                 return *this;
                             }

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     33
Monday, September 19, 2011
New Move Operations
                 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;
                 };

                                                     34
Monday, September 19, 2011
New Move Operations
                 struct Owner {
                     Owner(const Owner& src)



                             Owner& operator=(const Owner& src)




                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                                     34
Monday, September 19, 2011
New Move Operations
                 struct Owner {
                     Owner(const Owner& src)
                     Owner& operator=(const Owner& src)




                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };

                                              34
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);


                                                           •   X




                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                              35
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);


                                                           •   X




                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                              35
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }   •   X




                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     35
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }   •   X
              rvalue reference




                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     35
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }   •   X
              rvalue reference




                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     35
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }   •   X




                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     35
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }   •   X

                                                                            •



                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     35
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }   •   X

                                                                            •



                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     35
Monday, September 19, 2011
Move Constructor
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }   •   X

                                                                            •



                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     35
Monday, September 19, 2011
Move Assignment
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }


                                                                            •   Y

                                                                            •   Z

                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     36
Monday, September 19, 2011
Move Assignment
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }

                     Owner& operator=(Owner&& src) {
                         if (this == &src) return *this;
                                                                            •   Y
                         delete p;
                         p = src.p; src.p = 0;                              •   Z
                         return *this;
                      }
                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     36
Monday, September 19, 2011
Move Assignment
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }

                     Owner& operator=(Owner&& src) {
                         if (this == &src) return *this;
                                                                            •   Y
                         delete p;
                         p = src.p; src.p = 0;                              •   Z
                         return *this;
                      }
                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     36
Monday, September 19, 2011
Move Assignment
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }

                     Owner& operator=(Owner&& src) {
                         if (this == &src) return *this;
                                                                            •   Y
                         delete p;
                         p = src.p; src.p = 0;                              •   Z
                         return *this;
                      }
                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     36
Monday, September 19, 2011
Move Assignment
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }

                     Owner& operator=(Owner&& src) {
                         if (this == &src) return *this;
                                                                            •   Y
                         delete p;
                         p = src.p; src.p = 0;                              •
                         return *this;
                      }
                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     36
Monday, September 19, 2011
Move Assignment
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }

                     Owner& operator=(Owner&& src) {
                         if (this == &src) return *this;
                                                                            •   Y
                         delete p;
                         p = src.p; src.p = 0;                              •
                         return *this;
                      }
                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     36
Monday, September 19, 2011
Move Assignment
                 struct Owner {
                     Owner(const Owner& src);
                     Owner& operator=(const Owner& src);

                             Owner(Owner&& src) : p(src.p) { src.p = 0; }

                     Owner& operator=(Owner&& src) {
                         if (this == &src) return *this;
                                                                            •
                         delete p;
                         p = src.p; src.p = 0;                              •   Y
                         return *this;
                      }
                     ~Owner() { delete p; }
                 private:
                     Resource* p;
                 };
                                                     36
Monday, September 19, 2011
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
Containers
                   •         Move semantics

                   •         Hash containers

                   •         forward_list

                   •         array

                   •         tuple

                   •         Emplace

                   •         Allocators

                                               38
Monday, September 19, 2011
Other Useful Libraries


                   •         regex:

                   •         Algorithms

                   •         function / bind




                                               39
Monday, September 19, 2011
Smart Pointers


                   •         unique_ptr

                   •         shared_ptr




                                          40
Monday, September 19, 2011
Classes and OOP

                   •         member initializers

                   •         explict conversion

                   •         override and final

                   •         delegating and inheriting constructors

                   •         defaulted and deleted functions



                                                   41
Monday, September 19, 2011
Concurrency

                   •         async, futures, promise

                   •         locks, mutexes and condition variables

                   •         exception propagation

                   •         atomics




                                                42
Monday, September 19, 2011
Templates

                   •         Variadics

                   •         static_assert

                   •         local classes as template arguments

                   •         extern templates

                   •         Template aliases



                                                  43
Monday, September 19, 2011
Metaprogramming

                   •         constexpr

                   •         Template aliases

                   •         User-defined literals w/variadic templates

                   •         Type traits and extended SFINAE




                                                  44
Monday, September 19, 2011
What’s Next?
                   •         Modules


                   •         Concepts


                   •         Pythy Syntax:

                         •     []min(x, y) { return x < y ? x : y }


                                                    45
Monday, September 19, 2011

Más contenido relacionado

La actualidad más candente

C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
Vivek Das
 
Dr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot netDr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot net
Dr-archana-dhawan-bajaj
 
16 -ansi-iso_standards
16  -ansi-iso_standards16  -ansi-iso_standards
16 -ansi-iso_standards
Hector Garzo
 
05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
Hector Garzo
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
 

La actualidad más candente (20)

Reflection in Go
Reflection in GoReflection in Go
Reflection in Go
 
2 data and c
2 data and c2 data and c
2 data and c
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
C++ Chapter I
C++ Chapter IC++ Chapter I
C++ Chapter I
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
7 functions
7  functions7  functions
7 functions
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
Bit manipulation in atmel studio for AVR
Bit manipulation in atmel studio for AVRBit manipulation in atmel studio for AVR
Bit manipulation in atmel studio for AVR
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 
Cpp reference card
Cpp reference cardCpp reference card
Cpp reference card
 
Dr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot netDr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot net
 
16 -ansi-iso_standards
16  -ansi-iso_standards16  -ansi-iso_standards
16 -ansi-iso_standards
 
05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
Php operators
Php operatorsPhp operators
Php operators
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 

Destacado

Using classifiers to compute similarities between face images. Prof. Lior Wol...
Using classifiers to compute similarities between face images. Prof. Lior Wol...Using classifiers to compute similarities between face images. Prof. Lior Wol...
Using classifiers to compute similarities between face images. Prof. Lior Wol...
yaevents
 
Масштабируемость Hadoop в Facebook. Дмитрий Мольков, Facebook
Масштабируемость Hadoop в Facebook. Дмитрий Мольков, FacebookМасштабируемость Hadoop в Facebook. Дмитрий Мольков, Facebook
Масштабируемость Hadoop в Facebook. Дмитрий Мольков, Facebook
yaevents
 
Сложнейшие техники, применяемые буткитами и полиморфными вирусами. Вячеслав З...
Сложнейшие техники, применяемые буткитами и полиморфными вирусами. Вячеслав З...Сложнейшие техники, применяемые буткитами и полиморфными вирусами. Вячеслав З...
Сложнейшие техники, применяемые буткитами и полиморфными вирусами. Вячеслав З...
yaevents
 
Поисковая технология "Спектр". Андрей Плахов, Яндекс
Поисковая технология "Спектр". Андрей Плахов, ЯндексПоисковая технология "Спектр". Андрей Плахов, Яндекс
Поисковая технология "Спектр". Андрей Плахов, Яндекс
yaevents
 
Контроль зверей: инструменты для управления и мониторинга распределенных сист...
Контроль зверей: инструменты для управления и мониторинга распределенных сист...Контроль зверей: инструменты для управления и мониторинга распределенных сист...
Контроль зверей: инструменты для управления и мониторинга распределенных сист...
yaevents
 
В поисках математики. Михаил Денисенко, Нигма
В поисках математики. Михаил Денисенко, НигмаВ поисках математики. Михаил Денисенко, Нигма
В поисках математики. Михаил Денисенко, Нигма
yaevents
 
Зачем обычному программисту знать языки, на которых почти никто не пишет. Але...
Зачем обычному программисту знать языки, на которых почти никто не пишет. Але...Зачем обычному программисту знать языки, на которых почти никто не пишет. Але...
Зачем обычному программисту знать языки, на которых почти никто не пишет. Але...
yaevents
 
Юнит-тестирование и Google Mock. Влад Лосев, Google
Юнит-тестирование и Google Mock. Влад Лосев, GoogleЮнит-тестирование и Google Mock. Влад Лосев, Google
Юнит-тестирование и Google Mock. Влад Лосев, Google
yaevents
 
Сканирование уязвимостей со вкусом Яндекса. Тарас Иващенко, Яндекс
Сканирование уязвимостей со вкусом Яндекса. Тарас Иващенко, ЯндексСканирование уязвимостей со вкусом Яндекса. Тарас Иващенко, Яндекс
Сканирование уязвимостей со вкусом Яндекса. Тарас Иващенко, Яндекс
yaevents
 

Destacado (9)

Using classifiers to compute similarities between face images. Prof. Lior Wol...
Using classifiers to compute similarities between face images. Prof. Lior Wol...Using classifiers to compute similarities between face images. Prof. Lior Wol...
Using classifiers to compute similarities between face images. Prof. Lior Wol...
 
Масштабируемость Hadoop в Facebook. Дмитрий Мольков, Facebook
Масштабируемость Hadoop в Facebook. Дмитрий Мольков, FacebookМасштабируемость Hadoop в Facebook. Дмитрий Мольков, Facebook
Масштабируемость Hadoop в Facebook. Дмитрий Мольков, Facebook
 
Сложнейшие техники, применяемые буткитами и полиморфными вирусами. Вячеслав З...
Сложнейшие техники, применяемые буткитами и полиморфными вирусами. Вячеслав З...Сложнейшие техники, применяемые буткитами и полиморфными вирусами. Вячеслав З...
Сложнейшие техники, применяемые буткитами и полиморфными вирусами. Вячеслав З...
 
Поисковая технология "Спектр". Андрей Плахов, Яндекс
Поисковая технология "Спектр". Андрей Плахов, ЯндексПоисковая технология "Спектр". Андрей Плахов, Яндекс
Поисковая технология "Спектр". Андрей Плахов, Яндекс
 
Контроль зверей: инструменты для управления и мониторинга распределенных сист...
Контроль зверей: инструменты для управления и мониторинга распределенных сист...Контроль зверей: инструменты для управления и мониторинга распределенных сист...
Контроль зверей: инструменты для управления и мониторинга распределенных сист...
 
В поисках математики. Михаил Денисенко, Нигма
В поисках математики. Михаил Денисенко, НигмаВ поисках математики. Михаил Денисенко, Нигма
В поисках математики. Михаил Денисенко, Нигма
 
Зачем обычному программисту знать языки, на которых почти никто не пишет. Але...
Зачем обычному программисту знать языки, на которых почти никто не пишет. Але...Зачем обычному программисту знать языки, на которых почти никто не пишет. Але...
Зачем обычному программисту знать языки, на которых почти никто не пишет. Але...
 
Юнит-тестирование и Google Mock. Влад Лосев, Google
Юнит-тестирование и Google Mock. Влад Лосев, GoogleЮнит-тестирование и Google Mock. Влад Лосев, Google
Юнит-тестирование и Google Mock. Влад Лосев, Google
 
Сканирование уязвимостей со вкусом Яндекса. Тарас Иващенко, Яндекс
Сканирование уязвимостей со вкусом Яндекса. Тарас Иващенко, ЯндексСканирование уязвимостей со вкусом Яндекса. Тарас Иващенко, Яндекс
Сканирование уязвимостей со вкусом Яндекса. Тарас Иващенко, Яндекс
 

Similar a C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing

C++totural file
C++totural fileC++totural file
C++totural file
halaisumit
 

Similar a C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing (20)

Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
C++totural file
C++totural fileC++totural file
C++totural file
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
C++
C++C++
C++
 
python-2021.pdf
python-2021.pdfpython-2021.pdf
python-2021.pdf
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
C++17 not your father’s c++
C++17  not your father’s c++C++17  not your father’s c++
C++17 not your father’s c++
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
⚛️ Reasonable React (with beers)
⚛️ Reasonable React (with beers)⚛️ Reasonable React (with beers)
⚛️ Reasonable React (with beers)
 
Day 1
Day 1Day 1
Day 1
 
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
"О некоторых особенностях Objective-C++" Влад Михайленко (Maps.Me)
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
 
C++ Tutorial.docx
C++ Tutorial.docxC++ Tutorial.docx
C++ Tutorial.docx
 
Python introduction
Python introductionPython introduction
Python introduction
 

Más de yaevents

Как научить роботов тестировать веб-интерфейсы. Артем Ерошенко, Илья Кацев, Я...
Как научить роботов тестировать веб-интерфейсы. Артем Ерошенко, Илья Кацев, Я...Как научить роботов тестировать веб-интерфейсы. Артем Ерошенко, Илья Кацев, Я...
Как научить роботов тестировать веб-интерфейсы. Артем Ерошенко, Илья Кацев, Я...
yaevents
 
Тема для WordPress в БЭМ. Владимир Гриненко, Яндекс
Тема для WordPress в БЭМ. Владимир Гриненко, ЯндексТема для WordPress в БЭМ. Владимир Гриненко, Яндекс
Тема для WordPress в БЭМ. Владимир Гриненко, Яндекс
yaevents
 
Построение сложносоставных блоков в шаблонизаторе bemhtml. Сергей Бережной, Я...
Построение сложносоставных блоков в шаблонизаторе bemhtml. Сергей Бережной, Я...Построение сложносоставных блоков в шаблонизаторе bemhtml. Сергей Бережной, Я...
Построение сложносоставных блоков в шаблонизаторе bemhtml. Сергей Бережной, Я...
yaevents
 
i-bem.js: JavaScript в БЭМ-терминах. Елена Глухова, Варвара Степанова, Яндекс
i-bem.js: JavaScript в БЭМ-терминах. Елена Глухова, Варвара Степанова, Яндексi-bem.js: JavaScript в БЭМ-терминах. Елена Глухова, Варвара Степанова, Яндекс
i-bem.js: JavaScript в БЭМ-терминах. Елена Глухова, Варвара Степанова, Яндекс
yaevents
 
Дом из готовых кирпичей. Библиотека блоков, тюнинг, инструменты. Елена Глухов...
Дом из готовых кирпичей. Библиотека блоков, тюнинг, инструменты. Елена Глухов...Дом из готовых кирпичей. Библиотека блоков, тюнинг, инструменты. Елена Глухов...
Дом из готовых кирпичей. Библиотека блоков, тюнинг, инструменты. Елена Глухов...
yaevents
 
Модели в профессиональной инженерии и тестировании программ. Александр Петрен...
Модели в профессиональной инженерии и тестировании программ. Александр Петрен...Модели в профессиональной инженерии и тестировании программ. Александр Петрен...
Модели в профессиональной инженерии и тестировании программ. Александр Петрен...
yaevents
 
Администрирование небольших сервисов или один за всех и 100 на одного. Роман ...
Администрирование небольших сервисов или один за всех и 100 на одного. Роман ...Администрирование небольших сервисов или один за всех и 100 на одного. Роман ...
Администрирование небольших сервисов или один за всех и 100 на одного. Роман ...
yaevents
 
Мониторинг со всех сторон. Алексей Симаков, Яндекс
Мониторинг со всех сторон. Алексей Симаков, ЯндексМониторинг со всех сторон. Алексей Симаков, Яндекс
Мониторинг со всех сторон. Алексей Симаков, Яндекс
yaevents
 
Истории про разработку сайтов. Сергей Бережной, Яндекс
Истории про разработку сайтов. Сергей Бережной, ЯндексИстории про разработку сайтов. Сергей Бережной, Яндекс
Истории про разработку сайтов. Сергей Бережной, Яндекс
yaevents
 
Разработка приложений для Android на С++. Юрий Береза, Shturmann
Разработка приложений для Android на С++. Юрий Береза, ShturmannРазработка приложений для Android на С++. Юрий Береза, Shturmann
Разработка приложений для Android на С++. Юрий Береза, Shturmann
yaevents
 
Кросс-платформенная разработка под мобильные устройства. Дмитрий Жестилевский...
Кросс-платформенная разработка под мобильные устройства. Дмитрий Жестилевский...Кросс-платформенная разработка под мобильные устройства. Дмитрий Жестилевский...
Кросс-платформенная разработка под мобильные устройства. Дмитрий Жестилевский...
yaevents
 
Julia Stoyanovich - Making interval-based clustering rank-aware
Julia Stoyanovich - Making interval-based clustering rank-awareJulia Stoyanovich - Making interval-based clustering rank-aware
Julia Stoyanovich - Making interval-based clustering rank-aware
yaevents
 
Mike Thelwall - Sentiment strength detection for the social web: From YouTube...
Mike Thelwall - Sentiment strength detection for the social web: From YouTube...Mike Thelwall - Sentiment strength detection for the social web: From YouTube...
Mike Thelwall - Sentiment strength detection for the social web: From YouTube...
yaevents
 
Evangelos Kanoulas — Advances in Information Retrieval Evaluation
Evangelos Kanoulas — Advances in Information Retrieval EvaluationEvangelos Kanoulas — Advances in Information Retrieval Evaluation
Evangelos Kanoulas — Advances in Information Retrieval Evaluation
yaevents
 
Ben Carterett — Advances in Information Retrieval Evaluation
Ben Carterett — Advances in Information Retrieval EvaluationBen Carterett — Advances in Information Retrieval Evaluation
Ben Carterett — Advances in Information Retrieval Evaluation
yaevents
 
Raffaele Perego "Efficient Query Suggestions in the Long Tail"
Raffaele Perego "Efficient Query Suggestions in the Long Tail"Raffaele Perego "Efficient Query Suggestions in the Long Tail"
Raffaele Perego "Efficient Query Suggestions in the Long Tail"
yaevents
 
"Efficient Diversification of Web Search Results"
"Efficient Diversification of Web Search Results""Efficient Diversification of Web Search Results"
"Efficient Diversification of Web Search Results"
yaevents
 
Salvatore_Orlando
Salvatore_OrlandoSalvatore_Orlando
Salvatore_Orlando
yaevents
 
Fast dynamic analysis, Kostya Serebryany
Fast dynamic analysis, Kostya SerebryanyFast dynamic analysis, Kostya Serebryany
Fast dynamic analysis, Kostya Serebryany
yaevents
 
Adapting Rankers Online, Maarten de Rijke
Adapting Rankers Online, Maarten de RijkeAdapting Rankers Online, Maarten de Rijke
Adapting Rankers Online, Maarten de Rijke
yaevents
 

Más de yaevents (20)

Как научить роботов тестировать веб-интерфейсы. Артем Ерошенко, Илья Кацев, Я...
Как научить роботов тестировать веб-интерфейсы. Артем Ерошенко, Илья Кацев, Я...Как научить роботов тестировать веб-интерфейсы. Артем Ерошенко, Илья Кацев, Я...
Как научить роботов тестировать веб-интерфейсы. Артем Ерошенко, Илья Кацев, Я...
 
Тема для WordPress в БЭМ. Владимир Гриненко, Яндекс
Тема для WordPress в БЭМ. Владимир Гриненко, ЯндексТема для WordPress в БЭМ. Владимир Гриненко, Яндекс
Тема для WordPress в БЭМ. Владимир Гриненко, Яндекс
 
Построение сложносоставных блоков в шаблонизаторе bemhtml. Сергей Бережной, Я...
Построение сложносоставных блоков в шаблонизаторе bemhtml. Сергей Бережной, Я...Построение сложносоставных блоков в шаблонизаторе bemhtml. Сергей Бережной, Я...
Построение сложносоставных блоков в шаблонизаторе bemhtml. Сергей Бережной, Я...
 
i-bem.js: JavaScript в БЭМ-терминах. Елена Глухова, Варвара Степанова, Яндекс
i-bem.js: JavaScript в БЭМ-терминах. Елена Глухова, Варвара Степанова, Яндексi-bem.js: JavaScript в БЭМ-терминах. Елена Глухова, Варвара Степанова, Яндекс
i-bem.js: JavaScript в БЭМ-терминах. Елена Глухова, Варвара Степанова, Яндекс
 
Дом из готовых кирпичей. Библиотека блоков, тюнинг, инструменты. Елена Глухов...
Дом из готовых кирпичей. Библиотека блоков, тюнинг, инструменты. Елена Глухов...Дом из готовых кирпичей. Библиотека блоков, тюнинг, инструменты. Елена Глухов...
Дом из готовых кирпичей. Библиотека блоков, тюнинг, инструменты. Елена Глухов...
 
Модели в профессиональной инженерии и тестировании программ. Александр Петрен...
Модели в профессиональной инженерии и тестировании программ. Александр Петрен...Модели в профессиональной инженерии и тестировании программ. Александр Петрен...
Модели в профессиональной инженерии и тестировании программ. Александр Петрен...
 
Администрирование небольших сервисов или один за всех и 100 на одного. Роман ...
Администрирование небольших сервисов или один за всех и 100 на одного. Роман ...Администрирование небольших сервисов или один за всех и 100 на одного. Роман ...
Администрирование небольших сервисов или один за всех и 100 на одного. Роман ...
 
Мониторинг со всех сторон. Алексей Симаков, Яндекс
Мониторинг со всех сторон. Алексей Симаков, ЯндексМониторинг со всех сторон. Алексей Симаков, Яндекс
Мониторинг со всех сторон. Алексей Симаков, Яндекс
 
Истории про разработку сайтов. Сергей Бережной, Яндекс
Истории про разработку сайтов. Сергей Бережной, ЯндексИстории про разработку сайтов. Сергей Бережной, Яндекс
Истории про разработку сайтов. Сергей Бережной, Яндекс
 
Разработка приложений для Android на С++. Юрий Береза, Shturmann
Разработка приложений для Android на С++. Юрий Береза, ShturmannРазработка приложений для Android на С++. Юрий Береза, Shturmann
Разработка приложений для Android на С++. Юрий Береза, Shturmann
 
Кросс-платформенная разработка под мобильные устройства. Дмитрий Жестилевский...
Кросс-платформенная разработка под мобильные устройства. Дмитрий Жестилевский...Кросс-платформенная разработка под мобильные устройства. Дмитрий Жестилевский...
Кросс-платформенная разработка под мобильные устройства. Дмитрий Жестилевский...
 
Julia Stoyanovich - Making interval-based clustering rank-aware
Julia Stoyanovich - Making interval-based clustering rank-awareJulia Stoyanovich - Making interval-based clustering rank-aware
Julia Stoyanovich - Making interval-based clustering rank-aware
 
Mike Thelwall - Sentiment strength detection for the social web: From YouTube...
Mike Thelwall - Sentiment strength detection for the social web: From YouTube...Mike Thelwall - Sentiment strength detection for the social web: From YouTube...
Mike Thelwall - Sentiment strength detection for the social web: From YouTube...
 
Evangelos Kanoulas — Advances in Information Retrieval Evaluation
Evangelos Kanoulas — Advances in Information Retrieval EvaluationEvangelos Kanoulas — Advances in Information Retrieval Evaluation
Evangelos Kanoulas — Advances in Information Retrieval Evaluation
 
Ben Carterett — Advances in Information Retrieval Evaluation
Ben Carterett — Advances in Information Retrieval EvaluationBen Carterett — Advances in Information Retrieval Evaluation
Ben Carterett — Advances in Information Retrieval Evaluation
 
Raffaele Perego "Efficient Query Suggestions in the Long Tail"
Raffaele Perego "Efficient Query Suggestions in the Long Tail"Raffaele Perego "Efficient Query Suggestions in the Long Tail"
Raffaele Perego "Efficient Query Suggestions in the Long Tail"
 
"Efficient Diversification of Web Search Results"
"Efficient Diversification of Web Search Results""Efficient Diversification of Web Search Results"
"Efficient Diversification of Web Search Results"
 
Salvatore_Orlando
Salvatore_OrlandoSalvatore_Orlando
Salvatore_Orlando
 
Fast dynamic analysis, Kostya Serebryany
Fast dynamic analysis, Kostya SerebryanyFast dynamic analysis, Kostya Serebryany
Fast dynamic analysis, Kostya Serebryany
 
Adapting Rankers Online, Maarten de Rijke
Adapting Rankers Online, Maarten de RijkeAdapting Rankers Online, Maarten de Rijke
Adapting Rankers Online, Maarten de Rijke
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abrahams, BoostPro Computing

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