1 / 42

The future of C++

The future of C++. Herb Sutter 2-005. VC++ update: C++ at Microsoft. Beyond VC++ 2012.…. GoingNative 2012. C++’s biggest conference ever Here in Building 33: Sold out, 18 countries, 23 states Global live webcast: Over 20,000 viewers Global on demand: Over 600,000 viewers.

rusti
Télécharger la présentation

The future of C++

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The future of C++ Herb Sutter 2-005

  2. VC++ update: C++ at Microsoft • Beyond VC++ 2012.…

  3. GoingNative 2012 • C++’s biggest conference ever • Here in Building 33: Sold out, 18 countries, 23 states • Global live webcast: Over 20,000 viewers • Global on demand: Over 600,000 viewers

  4. Programming model Windows Store Apps Desktop Apps Windows Store Apps Desktop Apps HTML XAML C/C++ Win32 COM C#/VB .NET DX HTML XAML C#/VB .NET DX JavaScript C/C++ C#, VB JavaScript C/C++ C#, VB Stays Unchanged Native WinRT APIs Native WinRT APIs Devices & Printing Communication & Data Graphics & Media Devices & Printing Communication & Data Graphics & Media Fundamentals Fundamentals Core OS Core OS

  5. Visual C++ 2012 • Our biggest release in years • ARM targeting • Windows 8 tablet apps: WRL, C++/CX, XAML, DX • C++ AMP: partners + open specification • And more: auto-vectorizer, auto-parallelizer, parallel algorithms, thread-safe containers, “.then” continuations • Complete C++11 standard library + filesystem • C++11 enum class, range-for, override, final • Windows Phone 8 apps

  6. Visual C++ 2012 • Top requests • 1. C++11 conformance • 2. XP targeting • 3. Free “Express” compiler for desktop apps • Recent events • 3. Sep 12: Launched VS 2012…… and VS 2012 Desktop Express • 2. Oct 9: Released CTP of Windows XP targeting(full release in VS 2012 Update 1) • 1.

  7. Announced @GoingNative earlier this year… • “Out-of-band releases” • “Progressively roll out more C++11 features” • “Soon after VC++2012 ships”

  8. First batch…VC++ Compiler Nov 2012 CTP • “Compiler” = not library, IDE, debugger, code analysis • The stdlib doesn’t use the new features (yet) • IDE will give false red squiggles • /analyze may give false warnings • “CTP” = preview • Not go-live – preview, not production • Runs under VS2012

  9. Explicit conversion operatorsexplicit • “However, providing such a conversion would also makethe compiler uncomplainingly accept code which was semantic nonsense.” • – L. Goldthwaite et al., N1592 • Addresses “the other way” to write conversions. • C++11 example: template< /*...*/ > class unique_ptr {public: // ... explicit operator bool() const { return get() != nullptr; } • Because we want this to work: void f( unique_ptr<widget> ptr) { if( ptr ) { /*…*/ } • But we really didn’t mean for this to compile: use( ptr * 42 ); // oops, meant “(*ptr) * 42”…

  10. Raw string literalsR"(...)" • “Regular expressions use the same backslash escape sequence as C++ does in string literals. The resulting plethora of backslashesis very difficult to write correctly and impenetrable to read.” • – B. Dawes, N2053 • A “WYSIWYG” string that ignores escape sequences. • Wonderful for: filenames, regular expressions, HTML… • Compare this (C++11): auto x = R"(<BODY LINK="#0000ff" BGCOLOR="#ffffff"><P> </P><PRE>)";auto y = R"(('(?:[^\\']|\\.)*'|"(?:[^\\"]|\\.)*")|")"; • To this (C++98): char* x = "\n<BODY LINK=\"#0000ff\" BGCOLOR=\"#ffffff\">""\n<P> </P>\n<PRE>\n"; char* y = "('(?:[^\\\\']|\\\\.)*'|\"(?:[^\\\\\"]|\\\\.)*\")|";

  11. Function template default argumentsT=X • “[Fixing] a misbegotten remnant of the time when freestanding functions were treated as second class citizens.” • – B. Stroustrup, CoreDR 226 • Simpler than writing overloads. • Compare this container-based sort (C++11): template <typename C, typename F = less<typename C::value_type>>void Sort( C& c, F f = F() ) { sort(begin(c), end(c), f); } • To this (C++98): template <typename C, typename F>void Sort( C& c, F f ) { sort(begin(c), end(c), f); } template<typename C> // use <, like std::less doesvoid Sort( C& c ) { sort(begin(c), end(c); } • Useful even when all template parameters are deduced, as above.

  12. Delegating constructorsx() : x(…) • “The class maintainer has to write and maintain multiple constructors, [leading] to tedious code duplication atboth source andobject level.” • – Me and F. Glassborow, N1895 • Allow one constructor to delegate to another. • Can directly initialize bases and members without code duplication. class widget { string name; vector<int> data; public: widget( const string& s, int size ) : name(s), data(size) {} widget( const char* psz): widget( psz, 100 ){} widget() : widget("STL is great", 42) { cout<< "default"; } }; • C++98 workaround: Delegate to a common init function. • Doesn’t permit delegating base and member construction

  13. Q: Did you notice? The previous two examples showed some nice C++11 features… … but not proper C++11 style.

  14. Delegating constructorsx() : x(…) • “The class maintainer has to write and maintain multiple constructors, [leading] to tedious code duplication atboth source andobject level.” • – Me and F. Glassborow, N1895 • Allow one constructor to delegate to another. • Can directly initialize bases and members without code duplication. class widget { string name; vector<int> data; public: widget( const string& s, int size ) : name(s), data(size) {} widget( const char* psz): widget( psz, 100 ){} widget() : widget("STL is great", 42) { cout<< "default"; } }; • C++98 workaround: Delegate to a common init function. • Doesn’t permit delegating base and member construction

  15. Delegating constructorsx() : x(…) • “The class maintainer has to write and maintain multiple constructors, [leading] to tedious code duplication atboth source andobject level.” • – Me and F. Glassborow, N1895 • Allow one constructor to delegate to another. • Can directly initialize bases and members without code duplication. class widget { string name; vector<int> data; public: widget( const string& s, int size ) : name{s}, data{size} {} widget( const char* psz): widget{ psz, 100 }{} widget() : widget{"STL is great", 42} { cout<< "default"; } }; • C++98 workaround: Delegate to a common init function. • Doesn’t permit delegating base and member construction.

  16. Uniform initialization{ } • Consistent initialization capabilities and syntax. • Compare this (C++11): rectangle w { origin{}, extents{}}; complex<double> c { 2.71828, 3.14159 }; int a[] { 1, 2, 3, 4 }; vector<int> v { 1, 2, 3, 4 }; • To this (C++98): rectangle w(origin(), extents()); // oops... vexing complex<double> c( 2.71828, 3.14159 ); int a[] = { 1, 2, 3, 4 }; vector<int> v; for( int i = 1; i <= 4; ++i ) v.push_back(i); • “There is not one problem; there are several interrelated problems. Each individual problem can be solved relatively easily. The real problem is to provide a coherent solution…” • – B. Stroustrup and G. Dos Reis, N1890 Note: This one not in CTP (yet)

  17. Variadic templatesTs… • “Variadic templates are funadic.” • – A. Alexandrescu, GoingNative2012 • Type and parameter “packs.” template<typename...Ts> class widget { }; template<typename...Ts> void f( constTs&...ts ) { cout << sizeof...(Ts); } • Together with move/&&  perfect forwarding. • Given: void g( int, double );void g( int, string, widget, double );void g( int, gadget, double, double ); • Perfect forwarding: template<typename...Ts>void f( Ts&&...ts ) { g( 42, std::forward<Ts>(ts)..., 3.14 ); }

  18. VC++ Compiler Nov 2012 CTP • Features • explicit conversion operators • Raw string literals • Function template default arguments • Delegating constructors • Uniform initialization and initializer_lists • Variadictemplates • Available today: aka.ms/vc-ctp • With a tour: aka.ms/vc-ctp-tour

  19. VC++ next steps • Continue to deliver C++11 • More batches coming in 1H13 • Continue to investin platform support • Windows Store apps • Continue to bring C++/CX forward to solve problems like asynchrony • Continue to make extensions/rewrite less intrusive to existing C++ code • Example of both: await • Phone apps • See also: Writing C++ components on Windows 8 & Windows Phone 8 • Azure (e.g., Casablanca)

  20. ISO C++ update: C++ everywhere • Beyond C++11…

  21. First X3J16 meeting Somerset, NJ, USA (1990) Completed C++11 Madrid, Spain (2011)

  22. ISO C++ committee (WG21) attendance • Number of people willing to: • Journey avg(halfway, around,the,world)… • … at their own expense… • … and volunteer for 8am–10pm × 5–6day meetings? Completed C++11

  23. ISO C++ committee (WG21) attendance • Number of people willing to: • Journey avg(halfway, around,the,world)… • … at their own expense… • … and volunteer for 8am–10pm × 5–6day meetings? Completed C++11

  24. WG21 and {concurrency, parallelism} Approval Detailed Specification Design Investigation WG21 Core Library Evolution SG1 Concurrency SG2 Modules SG3 Filesystem SG4 Networking SG5 Tx. Memory SG6 Numerics SG7 Reflection SG8 Concepts SG9 Ranges SG10 Feature Test SG11 Databases

  25. ISO C++ timeline C++98 (major) C++03 (TC, bug fixes only) C++11 (major) C++14 (minor) C++17 (major) You arehere 98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 Library TR (aka TS) Performance TR FileSys TS TM TS? Net TS1 Net TS2 Net TS3

  26. What’s being discussed for the near term? (Tentative list) • Language • Generic lambdas (aka polymorphic lambdas) • Return type deduction from normal functions • “VLAs” – run-time-sized arrays as local variables • “static if” / “concepts lite” • Library • std:: literals (e.g., “xyzzy”s, 100b, “1,2.5”i, 123ms) • Reader-writer locks • Thread safety for streams • Concurrent queue and hashtable? • TS’s • File system – files, directories, paths • Networking – basic types, byte ordering

  27. ? • Q: How would you have heard about this?

  28. isocpp.org A center of gravity for C++ • A home base for C++’s Rebel Alliance model • A level of indirection to make existing sites and resources discoverable + extra original content = a “CNN + NY Times” for C++ For the broad C++ community, and like the community centered on ISO Standard C++ as the core Vendor-neutral and collaborative @isocpp

  29. isocpp.org @isocpp

  30. /blog /forums

  31. /get-started /tour

  32. /std /std/submit-a-proposal

  33. Goals Promote modernC++ style Increase portableC++ libraries • Obstacles • How do I learn C++? or get an overview of modern C++? • How do I find quality books? articles? talks? events? • Where can I discuss questions about the standard? • What is the committee doing, and who are they anyway? • How can I get involved and contribute to SG work? • How can I submit my own proposal? • How do I get early feedback on an idea? • What’s expected in a real proposal?

  34. Resources isocpp.org/get-started isocpp.org/blog isocpp.org/forums: std-discussion@isocpp.org isocpp.org/blog, /std isocpp.org/forums, /std isocpp.org/std/submit-a-proposal isocpp.org/forums: std-proposals@isocpp.org isocpp.org/std/library-design-guidelines Obstacles How do I learn C++? or get an overview of modern C++? How do I find quality books? articles? talks? events? Where can I discuss questions about the standard? What is the committee doing, and who are they anyway? How can I get involved and contribute to SG work? How can I submit my own proposal? • How do I get early feedback on an idea? • What’s expected in a real proposal?

  35. ?

  36. Standard C++ Foundation U.S. 501(c)(6) non-profit • Charter • To promote the understanding and use of Standard C++ on all compilers and platforms • “Organized exclusively for the improvement of business conditions for C++ software developers” • Trade association, not a new standards setting organization – ISO WG21 remains unchanged • Provides infrastructure and services to support the C++ standards committee and community • Vendor-neutral, all compilers and platforms • Independent, not controlled by any company

  37. Standard C++ Foundation U.S. 501(c)(6) non-profit • Founding Members Because investing in StandardC++ is good business

  38. Founding Directors Standard C++ Foundation U.S. 501(c)(6) non-profit Chandler Carruth(Google) BjarneStroustrup (TAMU) Beman Dawes (Boost) Herb Sutter (Microsoft) Stefanus Du Toit (Intel) Michael Wong (IBM)

  39. ISO C++ • Frequent and smaller releases • Next 24 months: • 3 Technical Specifications • 1 Standard • isocpp.org • Getting started + curated blog + open forums • Industry and committee news and updates • Over the winter: FAQ and more • Standard C++ Foundation • Promoting the understanding and use of Standard C++ on all compilers and platforms

  40. Resources • The Nov 2012 CTP: aka.ms/vc-ctp + STL’s video tour: aka.ms/vc-ctp-tour • Standard C++ status: isocpp.org/std/status • Standard C++ site: isocpp.org • Standard C++ Foundation: isocpp.org/about • Please submit session evals on the Build Windows 8 App or at http://aka.ms/BuildSessions • And come back at 2:30 (~45min) for live Q&A broadcast

More Related