c 0x the new c standard n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
C ++-0x : The New C++ Standard PowerPoint Presentation
Download Presentation
C ++-0x : The New C++ Standard

Loading in 2 Seconds...

play fullscreen
1 / 22
fagan

C ++-0x : The New C++ Standard - PowerPoint PPT Presentation

0 Views
Download Presentation
C ++-0x : The New C++ Standard
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. C++-0x: The New C++ Standard Jonathan Caves Principal Software Engineer Visual C++ Microsoft Corporation

  2. What is C++-0x? Revision to the existing C++ Standard - C++-03 Goals: to improve and simplify C++ Has been the focus of the C++ Committee since ~2004

  3. Major Features Concepts Memory Model/Concurrency Garbage Collection Other features

  4. Concepts • #include <list>#include <algorithm>extern void fill(std::list<int>&);int main(){ std::list<int> data; fill(data); std::sort(data.begin(), data.end());} • The problem:

  5. Concepts Containers Algorithms Iterators

  6. Concepts • The problem: • std::sort requires random access iterators • std::list doesn’t support random access iterators • Question: how can we make this information available to the compiler? • Answer: Concepts

  7. Concepts concept RandomAccessIterator<typename X> : BidirectionalIterator<X>{ X& operator+=(X&, difference_type); X operator+(X, difference_type); X operator+(difference_type, X); X& operator-=(X&, difference_type); X operator-(X, difference_type); difference_type operator-(X, X); reference operator[](X, difference_type); } Define the ‘concept’ of a random access iterator:

  8. Concepts template<typenameIter> requires : RandomAccessIterator<Iter>void sort(Iter begin, Iter end) { // ...} template<RandomAccessIteratorIter>void sort(Iter, Iter) { // ... } Define std::sort to require the RandomAccessIterator concept This is equivalent to:

  9. Concepts template<typename T> concept_mapRandomAccessIterator<T*> { typedef T value_type; typedef std::ptrdiff_tdifference_type; typedef T& reference; typedef T* pointer; }; Concepts Maps – provide the mapping between concepts and real types

  10. Concepts Want to know more: http://www.generic-programming.org/languages/conceptcpp/

  11. Concurrency Problem: C++-03 assumes a single threaded environment but most new computers are multi-core. How to enable C++ developers to efficiently write multi-threaded code?

  12. Concurrency Define a new C++ memory model Specify what it means to be a well formed C++ multi-thread application Will not change the runtime behavior of single threaded C++ applications

  13. Concurrency • Add library support for threading primitives • lock/release/fences/etc. • Add higher level library support for features like thread pooling and futures (maybe lambdas?) • Open Issues • What to do about destructors/exceptions? • Semantics of thread cancellation

  14. Garbage Collection struct S { }; void f(){ S* pS = new S();} The most “difficult” issue Enable GC for types that have a trivial destructor What is the interaction between code that expects GC and code that doesn’t?

  15. Variadic Templates template<typename T1> tuple<T1> make_tuple(T1& t1); template<typename T1, typename T2> tuple<T1, T2> make_tuple(T1& t1, T2& t2); template<typename T1, typename T2, typename T3> tuple<T1, T2, T3> make_tuple(T1& t1, T2& t2, T3& t3); template<typename T1, typename T2, typename T3, typename T4> tuple<T1, T2, T3, T4> make_tuple(T1& t1, T2& t2, T3& t3, T4& t4); ... Works like variadic macros except on template parameters. Great for types like std::tuple

  16. Variadic Templates template<typename... Types> tuple<Types...> make_tuple(Types&&...); With Variadic Templates there is just one make_tuple function:

  17. Rvalue References void f(int&); void f(int&&); int i; f(i); // calls f(int&) f(1); // calls f(int&&) Introduces a new kind of reference that can bind to an rvalue Allows perfect forwarding (move semantics).

  18. auto auto i = 4; std::vector<std::string> data; std::vector<std::string>::iteratoriter = data.begin(); auto iter = data.begin(); Finally a real use for ‘auto’

  19. decltype inti; decltype(i) // int decltype((i)) // int& template<typename T1, typename T2> auto f(T1 t1, T2 t2) -> decltype(t1 + t2){ } decltype – what is the type of this variable or expression?

  20. Other Features std::vector<std::list<int> > data; std::vector<std::list<int>> data; • Almost everything from TR-1 • The exception is the special math functions • C-99 Features • ‘long long’, variadic macros, __func__ • Allow ‘>>’ to terminate template argument lists

  21. Timeline Oct 2008 – Committee Draft (CD) Oct 2009 – Final Committee Draft (FCD) Oct 2010 – Draft International Standard (DIS) Early 2011 – International Standard

  22. Questions? Jonathan.Caves@microsoft.com