SlideShare a Scribd company logo
© Copyright SELA software & Education Labs Ltd. 14-18 Baruch Hirsch St.Bnei Brak 51202 Israel
                                      www.sela.co.il
C++11 status
(Some) New language features
(Some) New library features
Modern C++ style
• After more than a decade of contemplation . . .
• ISO C++11 Standard was published in September 2011
• Feature list: http://en.wikipedia.org/wiki/C%2B%2B11

• The Standard Library is part of the C++11 standard
• Some new features are upstream merges from TR1
• Visual Studio 2010: Some features are supported
• Visual Studio 2012: Some more features are supported


                                       Visual Studio 2012




                                                                          Not supported yet
     Visual Studio 2010




                          Automatic                         Concurrency                       Variadic
                          variables,                        library                           templates
                          decltype                          Memory                            Custom
                          Rvalue                            model                             literals
                          references                                                          Delegating
                          Lambda                                                              constructors
                          functions
• Comparison chart between many other compilers:
  http://s.sashag.net/rpST0u
Implicit variable declaration: The compiler knows what
  you mean
     (Almost) necessary for anonymous types
     Very convenient for complex templates
     Easily abused by lazy programmers!

std::map<...> M;
auto iter = M.begin(); //what’s the type of iter?
auto pair = std::make_pair(iter, M.key_range(...));
auto lambda = []() { ... }; //lambdas have an anonymous type
auto ptr = condition ? new class1 : new class2; //ERROR
auto x = 15; auto s = (string)"Hello"; //try to avoid...
Automatic iterator over arrays and STL collections
     Your collection will work – provide begin(), end(), and an
     input iterator over the elements
     Up to VC11 Beta: for each … in, a non-standard
     Microsoft extension

int numbers[] = ...;
for (int n : numbers) std::cout << n;
std::map<std::string,std::list<int>> M;
for (const auto& pair : M)
   for (auto n : pair.second)
        std::cout << pair.first << ' ' << pair.second;
Use a compile-time expression instead of a type name
  Can take the type of any expression
     Very useful for templates, forwarding etc.



float arr[15];
decltype(arr[0]) flt_ref = arr[0];
decltype(arr[1]+7) flt;
decltype(rand()) n = rand();

decltype(i+j) sum = i+j;
Your function can return a decltype
      Requires special syntax in these examples because the return
      type depends on parameter types

template <typename T1, typename T2>
auto multiply(const T1& t1, const T2& t2) -> decltype(t1+t2) {
   return t1 * t2;
}

template <typename InputIterator>
auto nth_element(InputIterator iter, int n) -> decltype(*iter) {
   while (--n > 0) ++iter;
   return *iter;
}
Initialize arrays, lists, vectors, other containers—and
  your own containers—with a natural syntax
      Not yet supported by Visual Studio 2012

vector<int> v { 1, 2, 3, 4 };
list<string> l = { “Tel-Aviv”, “Jerusalem” };
my_cont c { 42, 43, 44 };

class my_cont {
  public: my_cont(std::initializer_list<int> list) {
    for (auto it = list.begin(); it != list.end(); ++it) . . .
  }
};
int main() {
 [](){}();
 []{}();
} //this is legal C++,
 //although not useful
The current state of function objects and operations on
  them leaves much to be desired
  Must use arcane binding functions, placeholders, and
  rules to construct composite functors

class employee {
  public: void bonus(float commission, int vacation);
};
vector<int> employees;
std::for_each(employees.begin(), employees.end(),
  std::bind(std::mem_fn(&employee::bonus), _1, 0.25f, 3));
TR1 makes it somewhat easier to manipulate functors
  (functions and classes with operator())
  Doesn’t make it easier to create functors



std::function<bool(int,int)> g = greater<int>();
std::function<int(int,char**)> m = main;

std::function<bool(int)> greater_than17 = std::bind(g, _1, 17);
std::function<void(X*)> f = &X::foo; //foo is a member function
Inline methods in other methods (closures)
      Compile to an anonymous class that serves as a function object
      Rich capture semantics by value and by reference

auto print_num = [](int n) { std::cout << n; };
std::list<int> ns = ...;
std::for_each(ns.begin(), ns.end(), print_num);
int even = std::count_if(ns.begin(), ns.end(), [](int n) { return n&1==0;
   });

int x = 5;
[&x]() { ++x; }();      //capture by reference
[ x]() { ++x; }();      //capture by value. doesn’t compile!!
Default capture (use at your own risk)
  Mutable lambdas
  Explicit return value
int fib1 = 1, fib2 = 1;
auto next_step = [&]() { //default capture by reference
   int temp = fib2; fib2 = fib2 + fib1; fib1 = temp;
};
for (int i = 0; i < 20; ++i) next_step();

int n = 10;
auto say_yes_n_times = [=]() mutable ->bool { //default capture by value,
   return (--n > 0);                          //mutable and returns bool
};
std::function<...> to the rescue
  Freely manipulate lambdas as objects

auto identity = [](int x) {
   return [x]() { return x; };
};
auto next = [](const std::function<int(void)>& lambda) {
   return [&lambda]() { return lambda() + 1; };
};
auto _1 = identity(1);
auto _2 = next(_1);
auto _3 = next(_2);
std::cout << _1() << _2() << _3();
Recall our contrived bind(mem_fn(…)) example
      Use a lambda instead of composite functors
  Design your APIs with lambdas in mind
std::for_each(employees.begin(), employees.end(),
  std::bind(memfn(&employee::bonus), _1, 0.25f, 3));
std::for_each(employees.begin(), employees.end(),
  [](const employee& e) { e.bonus(0.25f, 3); });

template <typename Callback>
void enum_windows(const string& title, Callback callback) {
  . . . callback(current_window);
}
//or, use const std::function<void(const window&)>& as parameter
Lvalues are values that have a name
      Can appear on the left-hand-side of an assignment
  Rvalues are the rest
int x;
x = 42;       //OK, x has a name, it’s an lvalue
42 = x;       //Obviously wrong, 42 does not have a name, it’s an rvalue
x + 2 = 42;   //Also wrong, x + 2 returns a temporary, it’s an rvalue
x++ = 42;     //Also wrong, x++ returns a temporary, it’s an rvalue

int& foo();
int* goo();
--foo();      //OK, foo() returns an lvalue
++(*goo());   //OK, a dereferenced pointer is an lvalue
Turns out, this “standard” approach to references limits
  the performance of the language
  In this example, the contents of the vectors are COPIED
void init_vector(vector<int>& v);

vector<int> v, w;
init_vector(v); //no copy, we were careful to pass a reference
init_vector(w); //no copy, we were careful to pass a reference

swap(v, w);
//internally, swap will copy v to temp, w to v, temp to w, for a total
//of THREE MEMORY ALLOCATIONS AND DEALLOCATIONS!
//but how can we tell swap (and vector) to MOVE the contents around?
Rvalue references are references to rvalues!
      Standard references are to lvalues, const references may refer to
      temporary rvalues
      Enable move construction and assignment

my_array(const my_array& other) { //copy ctor
   dataptr_ = new T[size_ = other.size_];
   memcpy_s(dataptr_, size_*sizeof(T), other.dataptr_, size_*sizeof(T));
}
my_array& operator=(const my_array& other) { /*same deal*/ }
my_array& operator=(my_array&& other) {      //move assignment
   dataptr_ = other.dataptr_; size_ = other.size_;
   other.dataptr_ = nullptr; other.size_ = 0;
}
my_array(my_array&& other) {       //move ctor
   *this = std::move(other);       //NOTE: && is lvalue in the method body
}
• Much fewer copies of temporary objects float around
   – E.g. consider std::vector<T> with reallocation
   – Huge performance boost when your types are used in STL
   – Huge performance boost when using strings and other types
     with inner state that is expensive to copy
• Use auto, for each, initializer lists ubiquitously
• Don’t be afraid of returning objects by value
   – RVO, NRVO, and move constructors will minimize copies
• OK to design algorithms that require predicates,
  projections, and other functors
   – They will be easy to use—with lambda functions
• Use STL algorithms more widely with lambdas
Four standard unordered containers which use hash
  tables as their implementation
     unordered_map, unordered_set,
     unordered_multimap, unordered_multiset


set<string> names = { “Mike”, “Adam” };
assert(*names.begin() == “Adam”);

unordered_set<string> names = { “John”, “Abe” };
for (auto name : names)
  cout << name; //alphabetic order is NOT guaranteed
PERL-style regular expression facility offered by
  std::regex class and associated functions


regex version("(d+).(d+).(d+)");
string text = "2.0.50727";

cmatch captures;
if (regex_search(text.c_str(), captures, version)) {
  cout << "Major: " << captures[0] << endl;
  cout << "Build: " << captures[2] << endl;
}

//there’s also regex_replace for obvious purposes
• The standard library now has three types of smart
  pointers, eliminating the need to ever use delete

• If you are the sole owner of the object, use
  unique_ptr to make sure it’s deleted when the
  pointer dies (RAII)
• If you want to share the object with others, use
  shared_ptr—it will perform smart reference
  counting
• If you got yourself a cycle, use weak_ptr to break it!
Sole owner of an object
      Supports move semantics, but not copy semantics
  Replaces auto_ptr (which can’t move!)
unique_ptr<expensive_thing> create() {
  unique_ptr<expensive_thing> p(new expensive_thing);
  //...do some initialization, exceptions are covered by RAII
  return p;
}

unique_ptr<expensive_thing> p = create();   //move constructor used!

//another example is storing pointers in containers:
vector<unique_ptr<string>> v = { new string(“A”), new string(“B”) };
Thread-safe reference-counted pointer to an object
  with shared ownership
      When the last pointer dies, the object is deleted

struct file_handle {
  HANDLE handle;
  file_handle(const string& filename) ...
  ~file_handle() ... //closes the handle
};
class file {
  shared_ptr<file_handle> _handle;
public:
  file(const string& filename) : _handle(new file_handle(filename)) {}
  file(shared_ptr<file_handle> fh) : _handle(fh) {}
}; //can have multiple file objects over the same file_handle
Points to a shared object but does not keep it alive
   (does not affect reference count)
      The object may be destroyed “under our nose” at any time
   Breaks cycles between shared_ptrs

class employee {
  weak_ptr<employee> _manager;
  vector<shared_ptr<employee>> _direct_reports;
public:
  void beg_for_vacation(int days) {
    if (auto mgr = _manager.lock()) { mgr->beg(days); }   //mgr is shared_ptr
    else { /* your manager has been eliminated :-) */ }
  }
};
• Use smart pointers—no reason to have a delete
  statement in your code
  –   If you’re the only owner, use unique_ptr
  –   If you’re sharing the object, use shared_ptr
  –   Create shared_ptrs with make_shared()
  –   To prevent cycles, use weak_ptr
• Use the non-member begin() and end() functions
  – They work on arrays, and can be overloaded for types you
    don’t control
C++11 status
(Some) New language features
(Some) New library features
Modern C++ style
•   Bjarne Stroustrup’s FAQ: http://s.sashag.net/vWT1eI
•   C++11 Wikipedia article: http://s.sashag.net/vdSCW3
•   What’s New in VC++ 10: http://s.sashag.net/tb1fnr
•   What’s New in VC++ 11: http://s.sashag.net/sXy26y
•   More on rvalue references: http://s.sashag.net/uVLJ23
•   STL11 preliminary docs: http://s.sashag.net/vWR7sW
•   C++ memory model: http://s.sashag.net/rqsoDW
•   Modern C++ style: http://s.sashag.net/rP5DFl

More Related Content

What's hot

C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012 C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012
Sumant Tambe
 
C++11
C++11C++11
C++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingC++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect Forwarding
Francesco Casalegno
 
C++11
C++11C++11
Modern C++
Modern C++Modern C++
Modern C++
Michael Clark
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
CyberPlusIndia
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Languagemspline
 
Smart pointers
Smart pointersSmart pointers
Smart pointers
Vishal Mahajan
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
Dina Goldshtein
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
Francesco Casalegno
 
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
Mihai Todor
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
Sumant Tambe
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
Geeks Anonymes
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
daewon jeong
 
C++11 smart pointer
C++11 smart pointerC++11 smart pointer
C++11 smart pointerLei Yu
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
Bartlomiej Filipek
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabs
Stephane Gleizes
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
Carson Wilber
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Chris Adamson
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
Sumant Tambe
 

What's hot (20)

C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012 C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012
 
C++11
C++11C++11
C++11
 
C++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingC++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect Forwarding
 
C++11
C++11C++11
C++11
 
Modern C++
Modern C++Modern C++
Modern C++
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
Smart pointers
Smart pointersSmart pointers
Smart pointers
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
 
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
C++11 smart pointer
C++11 smart pointerC++11 smart pointer
C++11 smart pointer
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabs
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 

Viewers also liked

Distributed Systems Design
Distributed Systems DesignDistributed Systems Design
Distributed Systems Design
Dennis van der Stelt
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
Steven Smith
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingfarhan amjad
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Web Service Basics and NWS Setup
Web Service  Basics and NWS SetupWeb Service  Basics and NWS Setup
Web Service Basics and NWS Setup
Northeastern University
 
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Complement Verb
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
Northeastern University
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
乐群 陈
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo design
Confiz
 
SOLID Principles part 2
SOLID Principles part 2SOLID Principles part 2
SOLID Principles part 2
Dennis van der Stelt
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++
shammi mehra
 
SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
Dennis van der Stelt
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templatesfarhan amjad
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
farhan amjad
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
ShriKant Vashishtha
 
Building Embedded Linux
Building Embedded LinuxBuilding Embedded Linux
Building Embedded LinuxSherif Mousa
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
Liju Thomas
 
Keys to Continuous Delivery Success - Mark Warren, Product Director, Perforc...
Keys to Continuous  Delivery Success - Mark Warren, Product Director, Perforc...Keys to Continuous  Delivery Success - Mark Warren, Product Director, Perforc...
Keys to Continuous Delivery Success - Mark Warren, Product Director, Perforc...
Perforce
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARM
Sherif Mousa
 

Viewers also liked (19)

Distributed Systems Design
Distributed Systems DesignDistributed Systems Design
Distributed Systems Design
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
Web Service Basics and NWS Setup
Web Service  Basics and NWS SetupWeb Service  Basics and NWS Setup
Web Service Basics and NWS Setup
 
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo design
 
SOLID Principles part 2
SOLID Principles part 2SOLID Principles part 2
SOLID Principles part 2
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++
 
SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
 
Building Embedded Linux
Building Embedded LinuxBuilding Embedded Linux
Building Embedded Linux
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
 
Keys to Continuous Delivery Success - Mark Warren, Product Director, Perforc...
Keys to Continuous  Delivery Success - Mark Warren, Product Director, Perforc...Keys to Continuous  Delivery Success - Mark Warren, Product Director, Perforc...
Keys to Continuous Delivery Success - Mark Warren, Product Director, Perforc...
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARM
 

Similar to The Style of C++ 11

Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
Apache Traffic Server
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
Tomasz Kowalczewski
 
Whats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ DevelopersWhats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ Developers
Rainer Stropek
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
Santosh Rajan
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
CHOOSE
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAdam Getchell
 
Java 8
Java 8Java 8
Java 8
vilniusjug
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
jessitron
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
Mohsen Zainalpour
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
lennartkats
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
Doommaker
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
Andreas Dewes
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
Iwan van der Kleijn
 
The Future of C++
The Future of C++The Future of C++
The Future of C++
Sasha Goldshtein
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
JUG Lausanne
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
Abishek Purushothaman
 

Similar to The Style of C++ 11 (20)

Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
 
Whats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ DevelopersWhats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ Developers
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
Java 8
Java 8Java 8
Java 8
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
 
The Future of C++
The Future of C++The Future of C++
The Future of C++
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
 
Sysprog 9
Sysprog 9Sysprog 9
Sysprog 9
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
 

More from Sasha Goldshtein

Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
Sasha Goldshtein
 
The Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerThe Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF Primer
Sasha Goldshtein
 
Staring into the eBPF Abyss
Staring into the eBPF AbyssStaring into the eBPF Abyss
Staring into the eBPF Abyss
Sasha Goldshtein
 
Visual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET FrameworkVisual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET Framework
Sasha Goldshtein
 
Swift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSwift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS X
Sasha Goldshtein
 
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with XamarinC# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
Sasha Goldshtein
 
Modern Backends for Mobile Apps
Modern Backends for Mobile AppsModern Backends for Mobile Apps
Modern Backends for Mobile Apps
Sasha Goldshtein
 
.NET Debugging Workshop
.NET Debugging Workshop.NET Debugging Workshop
.NET Debugging Workshop
Sasha Goldshtein
 
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Sasha Goldshtein
 
Mastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionMastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and Production
Sasha Goldshtein
 
Introduction to RavenDB
Introduction to RavenDBIntroduction to RavenDB
Introduction to RavenDB
Sasha Goldshtein
 
State of the Platforms
State of the PlatformsState of the Platforms
State of the Platforms
Sasha Goldshtein
 
Delivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in MinutesDelivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in Minutes
Sasha Goldshtein
 
Building Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET BackendBuilding Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET Backend
Sasha Goldshtein
 
Building iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile ServicesBuilding iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile Services
Sasha Goldshtein
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
Sasha Goldshtein
 
Attacking Web Applications
Attacking Web ApplicationsAttacking Web Applications
Attacking Web Applications
Sasha Goldshtein
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile Services
Sasha Goldshtein
 
First Steps in Android Development
First Steps in Android DevelopmentFirst Steps in Android Development
First Steps in Android Development
Sasha Goldshtein
 
First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS Development
Sasha Goldshtein
 

More from Sasha Goldshtein (20)

Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
The Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF PrimerThe Next Linux Superpower: eBPF Primer
The Next Linux Superpower: eBPF Primer
 
Staring into the eBPF Abyss
Staring into the eBPF AbyssStaring into the eBPF Abyss
Staring into the eBPF Abyss
 
Visual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET FrameworkVisual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET Framework
 
Swift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSwift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS X
 
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with XamarinC# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
 
Modern Backends for Mobile Apps
Modern Backends for Mobile AppsModern Backends for Mobile Apps
Modern Backends for Mobile Apps
 
.NET Debugging Workshop
.NET Debugging Workshop.NET Debugging Workshop
.NET Debugging Workshop
 
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
 
Mastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionMastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and Production
 
Introduction to RavenDB
Introduction to RavenDBIntroduction to RavenDB
Introduction to RavenDB
 
State of the Platforms
State of the PlatformsState of the Platforms
State of the Platforms
 
Delivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in MinutesDelivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in Minutes
 
Building Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET BackendBuilding Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET Backend
 
Building iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile ServicesBuilding iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile Services
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
 
Attacking Web Applications
Attacking Web ApplicationsAttacking Web Applications
Attacking Web Applications
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile Services
 
First Steps in Android Development
First Steps in Android DevelopmentFirst Steps in Android Development
First Steps in Android Development
 
First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS Development
 

Recently uploaded

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 

The Style of C++ 11

  • 1. © Copyright SELA software & Education Labs Ltd. 14-18 Baruch Hirsch St.Bnei Brak 51202 Israel www.sela.co.il
  • 2. C++11 status (Some) New language features (Some) New library features Modern C++ style
  • 3. • After more than a decade of contemplation . . . • ISO C++11 Standard was published in September 2011 • Feature list: http://en.wikipedia.org/wiki/C%2B%2B11 • The Standard Library is part of the C++11 standard • Some new features are upstream merges from TR1
  • 4. • Visual Studio 2010: Some features are supported • Visual Studio 2012: Some more features are supported Visual Studio 2012 Not supported yet Visual Studio 2010 Automatic Concurrency Variadic variables, library templates decltype Memory Custom Rvalue model literals references Delegating Lambda constructors functions • Comparison chart between many other compilers: http://s.sashag.net/rpST0u
  • 5. Implicit variable declaration: The compiler knows what you mean (Almost) necessary for anonymous types Very convenient for complex templates Easily abused by lazy programmers! std::map<...> M; auto iter = M.begin(); //what’s the type of iter? auto pair = std::make_pair(iter, M.key_range(...)); auto lambda = []() { ... }; //lambdas have an anonymous type auto ptr = condition ? new class1 : new class2; //ERROR auto x = 15; auto s = (string)"Hello"; //try to avoid...
  • 6. Automatic iterator over arrays and STL collections Your collection will work – provide begin(), end(), and an input iterator over the elements Up to VC11 Beta: for each … in, a non-standard Microsoft extension int numbers[] = ...; for (int n : numbers) std::cout << n; std::map<std::string,std::list<int>> M; for (const auto& pair : M) for (auto n : pair.second) std::cout << pair.first << ' ' << pair.second;
  • 7. Use a compile-time expression instead of a type name Can take the type of any expression Very useful for templates, forwarding etc. float arr[15]; decltype(arr[0]) flt_ref = arr[0]; decltype(arr[1]+7) flt; decltype(rand()) n = rand(); decltype(i+j) sum = i+j;
  • 8. Your function can return a decltype Requires special syntax in these examples because the return type depends on parameter types template <typename T1, typename T2> auto multiply(const T1& t1, const T2& t2) -> decltype(t1+t2) { return t1 * t2; } template <typename InputIterator> auto nth_element(InputIterator iter, int n) -> decltype(*iter) { while (--n > 0) ++iter; return *iter; }
  • 9. Initialize arrays, lists, vectors, other containers—and your own containers—with a natural syntax Not yet supported by Visual Studio 2012 vector<int> v { 1, 2, 3, 4 }; list<string> l = { “Tel-Aviv”, “Jerusalem” }; my_cont c { 42, 43, 44 }; class my_cont { public: my_cont(std::initializer_list<int> list) { for (auto it = list.begin(); it != list.end(); ++it) . . . } };
  • 10. int main() { [](){}(); []{}(); } //this is legal C++, //although not useful
  • 11. The current state of function objects and operations on them leaves much to be desired Must use arcane binding functions, placeholders, and rules to construct composite functors class employee { public: void bonus(float commission, int vacation); }; vector<int> employees; std::for_each(employees.begin(), employees.end(), std::bind(std::mem_fn(&employee::bonus), _1, 0.25f, 3));
  • 12. TR1 makes it somewhat easier to manipulate functors (functions and classes with operator()) Doesn’t make it easier to create functors std::function<bool(int,int)> g = greater<int>(); std::function<int(int,char**)> m = main; std::function<bool(int)> greater_than17 = std::bind(g, _1, 17); std::function<void(X*)> f = &X::foo; //foo is a member function
  • 13. Inline methods in other methods (closures) Compile to an anonymous class that serves as a function object Rich capture semantics by value and by reference auto print_num = [](int n) { std::cout << n; }; std::list<int> ns = ...; std::for_each(ns.begin(), ns.end(), print_num); int even = std::count_if(ns.begin(), ns.end(), [](int n) { return n&1==0; }); int x = 5; [&x]() { ++x; }(); //capture by reference [ x]() { ++x; }(); //capture by value. doesn’t compile!!
  • 14. Default capture (use at your own risk) Mutable lambdas Explicit return value int fib1 = 1, fib2 = 1; auto next_step = [&]() { //default capture by reference int temp = fib2; fib2 = fib2 + fib1; fib1 = temp; }; for (int i = 0; i < 20; ++i) next_step(); int n = 10; auto say_yes_n_times = [=]() mutable ->bool { //default capture by value, return (--n > 0); //mutable and returns bool };
  • 15. std::function<...> to the rescue Freely manipulate lambdas as objects auto identity = [](int x) { return [x]() { return x; }; }; auto next = [](const std::function<int(void)>& lambda) { return [&lambda]() { return lambda() + 1; }; }; auto _1 = identity(1); auto _2 = next(_1); auto _3 = next(_2); std::cout << _1() << _2() << _3();
  • 16. Recall our contrived bind(mem_fn(…)) example Use a lambda instead of composite functors Design your APIs with lambdas in mind std::for_each(employees.begin(), employees.end(), std::bind(memfn(&employee::bonus), _1, 0.25f, 3)); std::for_each(employees.begin(), employees.end(), [](const employee& e) { e.bonus(0.25f, 3); }); template <typename Callback> void enum_windows(const string& title, Callback callback) { . . . callback(current_window); } //or, use const std::function<void(const window&)>& as parameter
  • 17. Lvalues are values that have a name Can appear on the left-hand-side of an assignment Rvalues are the rest int x; x = 42; //OK, x has a name, it’s an lvalue 42 = x; //Obviously wrong, 42 does not have a name, it’s an rvalue x + 2 = 42; //Also wrong, x + 2 returns a temporary, it’s an rvalue x++ = 42; //Also wrong, x++ returns a temporary, it’s an rvalue int& foo(); int* goo(); --foo(); //OK, foo() returns an lvalue ++(*goo()); //OK, a dereferenced pointer is an lvalue
  • 18. Turns out, this “standard” approach to references limits the performance of the language In this example, the contents of the vectors are COPIED void init_vector(vector<int>& v); vector<int> v, w; init_vector(v); //no copy, we were careful to pass a reference init_vector(w); //no copy, we were careful to pass a reference swap(v, w); //internally, swap will copy v to temp, w to v, temp to w, for a total //of THREE MEMORY ALLOCATIONS AND DEALLOCATIONS! //but how can we tell swap (and vector) to MOVE the contents around?
  • 19. Rvalue references are references to rvalues! Standard references are to lvalues, const references may refer to temporary rvalues Enable move construction and assignment my_array(const my_array& other) { //copy ctor dataptr_ = new T[size_ = other.size_]; memcpy_s(dataptr_, size_*sizeof(T), other.dataptr_, size_*sizeof(T)); } my_array& operator=(const my_array& other) { /*same deal*/ } my_array& operator=(my_array&& other) { //move assignment dataptr_ = other.dataptr_; size_ = other.size_; other.dataptr_ = nullptr; other.size_ = 0; } my_array(my_array&& other) { //move ctor *this = std::move(other); //NOTE: && is lvalue in the method body }
  • 20. • Much fewer copies of temporary objects float around – E.g. consider std::vector<T> with reallocation – Huge performance boost when your types are used in STL – Huge performance boost when using strings and other types with inner state that is expensive to copy
  • 21. • Use auto, for each, initializer lists ubiquitously • Don’t be afraid of returning objects by value – RVO, NRVO, and move constructors will minimize copies • OK to design algorithms that require predicates, projections, and other functors – They will be easy to use—with lambda functions • Use STL algorithms more widely with lambdas
  • 22. Four standard unordered containers which use hash tables as their implementation unordered_map, unordered_set, unordered_multimap, unordered_multiset set<string> names = { “Mike”, “Adam” }; assert(*names.begin() == “Adam”); unordered_set<string> names = { “John”, “Abe” }; for (auto name : names) cout << name; //alphabetic order is NOT guaranteed
  • 23. PERL-style regular expression facility offered by std::regex class and associated functions regex version("(d+).(d+).(d+)"); string text = "2.0.50727"; cmatch captures; if (regex_search(text.c_str(), captures, version)) { cout << "Major: " << captures[0] << endl; cout << "Build: " << captures[2] << endl; } //there’s also regex_replace for obvious purposes
  • 24. • The standard library now has three types of smart pointers, eliminating the need to ever use delete • If you are the sole owner of the object, use unique_ptr to make sure it’s deleted when the pointer dies (RAII) • If you want to share the object with others, use shared_ptr—it will perform smart reference counting • If you got yourself a cycle, use weak_ptr to break it!
  • 25. Sole owner of an object Supports move semantics, but not copy semantics Replaces auto_ptr (which can’t move!) unique_ptr<expensive_thing> create() { unique_ptr<expensive_thing> p(new expensive_thing); //...do some initialization, exceptions are covered by RAII return p; } unique_ptr<expensive_thing> p = create(); //move constructor used! //another example is storing pointers in containers: vector<unique_ptr<string>> v = { new string(“A”), new string(“B”) };
  • 26. Thread-safe reference-counted pointer to an object with shared ownership When the last pointer dies, the object is deleted struct file_handle { HANDLE handle; file_handle(const string& filename) ... ~file_handle() ... //closes the handle }; class file { shared_ptr<file_handle> _handle; public: file(const string& filename) : _handle(new file_handle(filename)) {} file(shared_ptr<file_handle> fh) : _handle(fh) {} }; //can have multiple file objects over the same file_handle
  • 27. Points to a shared object but does not keep it alive (does not affect reference count) The object may be destroyed “under our nose” at any time Breaks cycles between shared_ptrs class employee { weak_ptr<employee> _manager; vector<shared_ptr<employee>> _direct_reports; public: void beg_for_vacation(int days) { if (auto mgr = _manager.lock()) { mgr->beg(days); } //mgr is shared_ptr else { /* your manager has been eliminated :-) */ } } };
  • 28. • Use smart pointers—no reason to have a delete statement in your code – If you’re the only owner, use unique_ptr – If you’re sharing the object, use shared_ptr – Create shared_ptrs with make_shared() – To prevent cycles, use weak_ptr • Use the non-member begin() and end() functions – They work on arrays, and can be overloaded for types you don’t control
  • 29. C++11 status (Some) New language features (Some) New library features Modern C++ style
  • 30.
  • 31. Bjarne Stroustrup’s FAQ: http://s.sashag.net/vWT1eI • C++11 Wikipedia article: http://s.sashag.net/vdSCW3 • What’s New in VC++ 10: http://s.sashag.net/tb1fnr • What’s New in VC++ 11: http://s.sashag.net/sXy26y • More on rvalue references: http://s.sashag.net/uVLJ23 • STL11 preliminary docs: http://s.sashag.net/vWR7sW • C++ memory model: http://s.sashag.net/rqsoDW • Modern C++ style: http://s.sashag.net/rP5DFl

Editor's Notes

  1. The standardsyntax also allows for (auto&amp; n : numbers) { ++n; }, i.e. going over the elements with a mutable iterator.The Microsoft syntax allows this as well, with for each (auto&amp; n in numbers) { ++n; }.
  2. VC11 does not support initializer lists yet.More examples for uniform initialization:struct X { X(inti, int j); };void f(X);f({1,2});std::complex&lt;double&gt; c {1.0,1.0};
  3. std::bind and std::mem_fn are really state-of-the-art (from TR1) considering the state of affairs using vanilla C++98.Namely, we had pointer_to_unary_function, bind1st, bind2nd, and similar stuff.
  4. Mention that stateless lambdas (beginning with [], such that they don’t capture any local variables) are implicitly convertible to function pointers. (But only in VS11 :-))
  5. There is a slightly complicated point in the move constructor here. If the move constructor were to use the assignment directly, e.g. *this = other, then the standard operator= would be called. The reason is that rvalue references are treated as lvalues as long as they have a name. What std::move does is pass its parameter through, and by doing that it removes its name so the caller treats it as an unnamed object, and hence an rvalue. (The reason for this quirk, in turn, is to prevent accidental moves that will destroy the object. E.g. you could move from other, and then attempt to use other later in your method.)After we have a container that works like this, we can also have an std::swap that works appropriately—it will simply use std::move instead of just the assignment operator to move the swapped data around (through a temporary variable), i.e.: temp = move(a); a = move(b); b = move(temp); — and no copies of the contents are required.
  6. Note that Microsoft had stdext::hash_map previously, and nearly everyone else did, too. Unclear how this will merge in.There is another new kind of collection—std::array&lt;T,N&gt;—which is a compile-time sized array with begin() and end() member functions for use with STL collections requiring an iterator in a natural fashion.