One C++
Herb Sutter
Themes: Understanding the C++ Tide
OrganizationMomentumPopulation shift (with just a little code)Trajectory
Visual C++ Roadmap Update
ISO C++ UpdatePortable C++ Libraries UpdateOne C++
Agenda
Conformance roadmap: The road to C++14VC++ 2013
PreviewShipped in June
VC++ 2013 RTMlater this year
Explicit conversion operators
Non-static data member initializers
Raw string literals = default
Function template default arguments = delete
Delegating constructors
“using” aliasesC++14 libs: type
aliasesUniform init & initializer_lists
C99 variable declsC99 _Bool
Variadic templates C99 compound literals
C++14 libs: cbegin/ greater<>/make_uni
queC99 designated
initializers
JUN'13
Conformance roadmap: The road to C++14VC++ 2013
PreviewShipped in June
VC++ 2013 A preview
updatewill be available
this monthExplicit conversion
operatorsNon-static data
member initializers
Raw string literals = default
Function template default arguments = delete
Delegating constructors
“using” aliasesC++14 libs: type
aliasesUniform init & initializer_lists
C99 variable declsC99 _Bool
Variadic templates C99 compound literals
C++14 libs: cbegin/ greater<>/make_uni
queC99 designated
initializers
Conformance roadmap: The road to C++14 waveVC++ 2013
PreviewShipped in June
VC++ 2013 A preview
updatewill be available
this monthExplicit conversion
operatorsNon-static data
member initializers__func__
Extended sizeofThread-safe
function local static init
Unrestricted unions Attributes
Raw string literals = default Implicit move generation User-defined literals
Universal character
names in literalsthread_local
Function template default arguments = delete Ref-qualifiers:
& and && for *this noexcept Expression SFINAE
C++11 preprocessor
(incl. C++98 & C11)
Delegating constructors
“using” aliasesC++14 libs: type
aliasesC++14 generalized
lambda capturealignofalignas
Inheriting constructors
C++98 two-phase lookup
Uniform init & initializer_lists
C99 variable declsC99 _Bool
C++14 auto function return type
deductionconstexpr (except
ctors / literal types)constexpr
(literal types)C++14
generalized constexpr
Variadic templates C99 compound literals
C++14 generic lambdas
C++14 decltype(auto)
Inline namespaces
C++14 dyn. arraysC++14 var templates
C++14 libs: cbegin/ greater<>/make_uni
queC99 designated
initializersC++TS?
async/awaitC++14 libs: std::
user-defined literalschar16_t, char32_t
C++TS concepts lite
Post-RTM OOB CTPWhat we’re currently implementing, roughly in order… some subset in
CTP
PlannedWhat’s next for full conformance
JUN'13
unconditional
Conformance roadmap: The road to C++14 wave
__func__Extended sizeof
Thread-safe function local static
initUnrestricted
unions Attributes
Implicit move generation User-defined literals
Universal character
names in literalsthread_local
Ref-qualifiers: & and && for *this noexcept Expression
SFINAE
C++11 preprocessor
(incl. C++98 & C11)
C++14 generalized lambda capture
alignofalignas
Inheriting constructors
C++98 two-phase lookup
C++14 auto function return type
deductionconstexpr (except
ctors / literal types)constexpr
(literal types)C++14
generalized constexpr
C++14 generic lambdas
C++14 decltype(auto)
Inline namespaces
C++14 dyn. arraysC++14 var templates
C++TS? async/await
C++14 libs: std:: user-defined literals
char16_t, char32_t
C++TS concepts lite
Post-RTM OOB CTP – 4Q13What we’re currently implementing, roughly in order… some subset in
CTP
PlannedWhat’s next for full conformance
high probability in CTP
med probability in CTP
unconditional
Conformance roadmap: The road to C++14 waveVC++ 2013
PreviewShipped in June
VC++ 2013 RCAvailable today
Explicit conversion operators
Non-static data member initializers
__func__Extended sizeof
Thread-safe function local static
initUnrestricted
unions Attributes
Raw string literals = default Implicit move generation User-defined literals
Universal character
names in literalsthread_local
Function template default arguments = delete Ref-qualifiers:
& and && for *this noexcept Expression SFINAE
C++11 preprocessor
(incl. C++98 & C11)
Delegating constructors
“using” aliasesC++14 libs: type
aliasesC++14 generalized
lambda capturealignofalignas
Inheriting constructors
C++98 two-phase lookup
Uniform init & initializer_lists
C99 variable declsC99 _Bool
C++14 auto function return type
deductionconstexpr (except
ctors / literal types)constexpr
(literal types)C++14
generalized constexpr
Variadic templates C99 compound literals
C++14 generic lambdas
C++14 decltype(auto)
Inline namespaces
C++14 dyn. arraysC++14 var templates
C++14 libs: cbegin/ greater<>/make_uni
queC99 designated
initializersC++TS?
async/awaitC++14 libs: std::
user-defined literalschar16_t, char32_t
C++TS concepts lite
PlannedWhat’s next for full conformance
Post-RTM OOB CTP – 4Q13What we’re currently implementing, roughly in order… some subset in
CTP
Visual C++ Roadmap UpdateISO C++ Update
Portable C++ Libraries UpdateOne C++
Agenda
You arehere
ISO C++: A Living Language
98 99 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18
C++98(major)
Library TR1 (aka TS) Performance TR
C++03(TC, bug fixes only)
C++11(major)
C++17(major)
C++14(minor)
FileSysTSNetTS1Concepts
TS
14
2014++ cadenceThis ISO C++ revision cycle: faster, more predictable
Less monolithic: Delivering concurrent and decoupled library & language
extensionsC++ is a living language
Each round of international comment ballots generates bugs, tweaks, and requests
C++14: Stability
C++11 CD C++11 DIS C++14 CD0
100
200
300
400
500
600# Comments to address in ballot reso-
lution
Each round of international comment ballots generates bugs, tweaks, and requests
C++14: Stability
C++11 CD C++11 DIS C++14 CD0
100
200
300
400
500
600# Comments to address in ballot reso-
lution
Visual C++ Roadmap UpdateISO C++ UpdatePortable C++ Libraries Update
One C++
Agenda
C++11
C++98 + TR1C++11
Portable C++
C++98 C++98
language library
proxies for size comparisons: spec #pages, book #pagesGN’12
proxies for size comparisons: spec #words library #types (non-‘plumbing’)
2008 .NET FX + VS Pro Libs
Java SE 7
C++11
Portable C++language
C# 3.0 (2008)Java 7 (2011)
2008 .NET FX (only)
C++11
library
GN’12
2008 .NET FX + VS Pro Libs
Java SE 7
C++11
C# 3.0 (2008)Java 7 (2011)
2008 .NET FX (only)
Portable C++
C++11
language library
GN’12
C++11
C# 3.0 (2008)Java 7 (2011)
Portable C++
?C++11
library“All in all, this [C++0x and post-C++0x library wish lists] … is not quite the
‘ambitious and opportunistic’ policy that I had hoped for in 2001 (§8). However, people who scream for more (such as me) should note
that even what’s listed above will roughly double the size of the
standard library.”
– B. Stroustrup, HoPL-III, 2007
GN’12
Portable C++ Library (PCL) Goals:
Large set of useful and current libraries. Available on all major platforms. Shipped with and supported by C++ implementations. And composable, using consistent types.
Minimum: De facto availability as part of all major compiler products. Ideal: De jure inclusion in Standard C++.
GN’12
Wonderful! But… … where are we going to find all these libraries?
WG21PCL
GN’12
Portable C++ Librariesad-hoc
De Jure: The Standard
De jure librariesstd::HorizontalShip in the box
ad-hoc
Challenge
Make the world’s most flexible and efficient library-building language better for building libraries and bundle more broadly useful libraries
Challenge, Part 2
‘Who will specify all these libraries? To make it happen, we must involve new people, not just ask for more work from today’s committee members.’
– B. Stroustrup, Kona, Feb 6, 2012
Thanks to all the volunteers!
ISO C++ (WG21) attendance
Sep 2008
Mar 2009
Jul 2009
Oct 2009
Mar 2010
Aug 2010
Nov 2010
Mar 2011
Aug 2011
Feb 2012
Oct 2012
Apr 2013
Sep 2013
0
20
40
60
80
100
Meeting size (#attendees)
CompletedC++11
CompletedC++14
CD
wg21core / ewg
lib / lewg
sg1sg8
…
sg4
3
……
…
……
…
…
…
Lib Evolution WG
Library WG
WG21 OrganizationWG21 – Full Committee
Evolution WG
Core WG
SG5Tx. Memory
SG2Modules
SG6Numerics
SG4Networking
SG3Filesystem
SG7Reflection
SG8Concepts
SG9Ranges
SG10Feature Test
SG11Databases
SG12U. Behavior
SG1Conc. & Parall.
Lang ExtensionLib buildingLib composabilityBase LibsDomain Libs
---
---
--
----
-
---
Update: SG1 July Meeting, Santa ClaraConcurrency TS1 (2014?)All of:• std::future Extensions:
then, wait_any, wait_all• Executors• Resumable Functions:
await (with futures)+ If ready (else TS2):• Counters• Queues• Concurrent containers: concurrent_vector,
unordered associative containers• Latches and barriers• upgrade_lock?
Parallelism TS1At least one of:• Parallel algorithms (e.g., Parallel STL)• Data-based parallelism• Task-based parallelism
+ If ready (else TS2)• MapReduce• Pipelines?
Bringing state-of-the-art concurrency and parallelism
to Standard C++
Lib Evolution WG
Library WG
WG21 OrganizationWG21 – Full Committee
Evolution WG
Core WG
SG5Tx. Memory
SG2Modules
SG6Numerics
SG4Networking
SG3Filesystem
SG7Reflection
SG8Concepts
SG9Ranges
SG10Feature Test
SG11Databases
SG12U. Behavior
SG1Conc. & Parall.
Lang ExtensionLib buildingLib composabilityBase LibsDomain Libs
---
---
--
----
-
---
(SG13)2D Graphics
Thanks, Tom et al.!
Reality check
Nobody knows what “most” C++ programmers do.
— Bjarne Stroustrup
Planetary
Language: C++
Primary author: Robert HodginSelf taught programmerSculpture major at RISD
Q: Which language would you recommend for creative graphics apps written by non-CS majors?
Q: Which language would you recommend for creative graphics apps written by non-CS majors?
Did you know?C++ library openFrameworks is widely used in teaching art & design• Incl. prestigious schools like
Parsons School for DesignC++ “creative coding” library Cinder awarded ad industry’s highest honor• June 2013: Cannes Lions
Festival, Innovation Grand PrixC++ app Planetary acquired by Smithsonian• August 2013: The museum’s
first-ever curation/preservation of code
From the trenches
The advertising and design industries have really embraced C++ in recent years for a new generation of interactive projects.I think that’s largely because in our work, a piece of software’s performance often marks the difference between a user’s experience feeling ordinary and feeling magical.This [2013] has been an excellent year for C++’s visibility in the art and design worlds…
— Andrew Bell
Who did/do I want it for?• Primary concerns
– Systems programming– Embedded systems– Resource constrained systems– Large systems
• Experts– “C++ is expert friendly”
• Novices– C++ Is not just expert friendly
Stroustrup - Essence - Going Naive'13 33
GN’13Stroustrup
How Easy Is C++, Really?
// First thing Scott said:
cout << “Is that on a scale of 10 to 20?\n”
#include <iostream> #include <algorithm> #include <vector> using namespace std;
int main() { vector<int> v; int i = 0; cout << "Please enter some numbers: "; while( cin >> i ) v.push_back(i); sort( begin(v), end(v) ); cout << "Here are those numbers, sorted:"; for( auto& e : v ) cout << ' ' << e; cout << endl;}
How Easy Is C++, Really? 15 LOC Example
Reality check
C++ is about exploiting the machine
Standard C++ doesn’t exploit my 1979 Atari
Image credit:Bilby (via Wikipedia)
Addressable text modes: get/set (x,y)Graphics modes up to 320x192 @ 1.5 colors
#include "cinder/app/AppBasic.h"#include "cinder/dx/dx.h"#include <vector>using namespace ci;using namespace ci::app;
class MyApp : public AppBasic { std::vector<Vec2f> points;public: void mouseDrag( MouseEvent e ) { points.push_back(e.getPos()); } void draw() { dx::clear( Color( 0.1f, 0.1f, 0.15f ) ); dx::color( 1.0f, 0.5f, 0.25f ); dx::begin( GL_LINE_STRIP ); for( auto& e : points ) dx::vertex(e); dx::end(); }};CINDER_APP_BASIC( MyApp, RendererDx )
How Easy Is C++, Really? 18 LOC Example
How Easy Is C++, Really? 200 LOC Example
Time: One afternoon• From scratch, incl. installing &
learning Cinder, and incl. 1h lost on a GL bug
Line count (nonempty)9: #include / using34: data86: game logic60: graphics + input• Including board display, player
animation, powerup color flashing
and warning transitions, …
5%18%45%32%
Q: How many people here are developers?
Q2: How many of you brought a compiler?
Q3: … and used it already?Gauntlet: What creative graphics app can you build tonight?• Use a favorite compiler and target
OS• From scratch = empty project• Using only Standard C++ plus
either openFrameworks (openframeworks.cc) or Cinder (libcinder.org; for DX, search “cinder site:msdn.com”)
Email your name and screenshot(s)/video to [email protected]
Tell us about it for 2 min tomorrow
This is what I built from
scratch in an afternoon
Slide courtesy Rick Barraza
Slide courtesy Rick Barraza
Slide courtesy Rick Barraza
Slide courtesy Rick Barraza
Slide courtesy Rick Barraza
Slide courtesy Rick Barraza
Just Getting Organized: 2D Graphics“Draft” proposed initial scopeInitial thinking, subject to change:• Modern C++11/14 API for 2D + text. Audio
and 3D separate, but combinable (e.g., 2D as HUD over 3D). Flexible, not a “game engine.” Thin, not a new platform or Big-F Framework.
• Immediate mode + sprites/particles/input. Later: retained mode.
• Included-but-optional default graphics loop.• native_handle hook. Implementable on at
least DX & OpenGL + native_handle gateway to platform-specific code.
• Asset loading/construction hook. Included-but-optional default “load asset from file” + simple way to plug into user’s asset system (maybe ‘load from memory’ suffices?).
Major C++ graphics librariesInviting participation from:• openFrameworks• Cinder• SFML• LibSDL• Qt• DirectXTK• Cocos2D• Graphucks• Hieroglyph• …
PCL Scope Do focus on pure libraries. Do focus on common modern tasks with state-of-the-art existing practice.
Lower-level: Message queue, ranges + range algorithms, parallel algorithms, thread-safe containers, continuations (future.then), async I/O, file system, networking/sockets, serialization.
Higher-level: REST web services, sensor fusion, HTTP, HTML, XML/XSLT, JSON, persistence, settings/preferences, compression, cryptography, audio/image/video, databases, SMS messaging.
Don’t target niche uses. (Example: Sci-eng linear algebra.) Don’t become a platform = fat libs that duplicate native services. Don’t attempt to define a “portable cross-platform” library that will be
inferior to a native platform app. (Example: GUI WIMP widgets.)
GN’12
PCL Scope Do focus on pure libraries. Do focus on common modern tasks with state-of-the-art existing practice.
Lower-level: Message queue, ranges + range algorithms, parallel algorithms, thread-safe containers, continuations (future.then), async I/O, file system, networking/sockets, serialization.
Higher-level: REST web services, sensor fusion, HTTP, HTML, XML/XSLT, JSON, persistence, settings/preferences, compression, cryptography, audio/image/video, databases, SMS messaging.
Don’t target niche uses. (Example: Sci-eng linear algebra.) Don’t become a platform = fat libs that duplicate native services. Don’t attempt to define a “portable cross-platform” library that will be
inferior to a native platform app. (Example: GUI WIMP widgets.)
Lower-level: Message queue, ranges + range algorithms, parallel algorithms, thread-safe containers, continuations (future.then), async I/O, file system, networking/sockets, serialization.
Higher-level: REST web services, sensor fusion, HTTP, HTML, XML/XSLT, JSON, persistence, settings/preferences, compression, cryptography, audio/image/video, databases, SMS messaging.
GN’12
Next: De Facto“De facto” portable librariesFew exemplars today (e.g., core Boost)• Find by word of mouth• Download and install on your own
Q: What more is needed?Think “PyPI + apt-get” for C++ libs• Discovery: Catalog, filtering,
reviews• Acquisition: Package management,
installation, project integrationNascent today: MacPorts, NuGet (Fri)
ad-hoc
de facto
de jure
Visual C++ Roadmap UpdateISO C++ UpdatePortable C++ Libraries UpdateOne C++
Agenda
Observation
The world has never had “One C++”
Standard vs. implementationsHaving a standard is great.But: Multi-year lag until (mostly) conforming implementations available.
Implementation A vs. implementation BVendors implementing the standard is great.But: Vendor A implements different snapshots of draft standard features than vendor B, while the standard is still changing. (Example: &&.)But: Vendor A implements features in a different order than vendor B.
“The nice thing about standards is that there are so many to choose from.”
— Andrew Tanenbaum
s/standards/de facto implementations/
The world has never had “One C++”
198x-1998: Pre-Standard Wild WestCompeting template instantiation models, etc.What’s this “STL” you speak of?1998-2003: Partial convergenceCompilers implemented features in different ordersSome features were never widely implemented: export, std:: hoisting2003-2011: C++0x — for(;;) ++x;Compilers implemented different versions of features in different orders“Each did that which was right in his own eyes”2011-2013: Approaching first convergenceDigesting a decade-sized package of features once it stopped changing
“The nice thing about standards is that there are so many to choose from.”
— Andrew Tanenbaum
s/standards/de facto implementations/
The world has never had “One C++”
This has been a landmark summerMay 31: GCC 4.8.1 ships complete C++11 language• 4.9 to have complete C++11 lang & lib
June 5: Clang 3.3 ships complete C++11 lang & lib
Comparison: Time to full conformanceC++98: 5 years* (2003, EDG + Dinkumware)C++11: 2 years (2013, Clang)C++14: 0 years (2014, probably multiple)
“The nice thing about standards is that there are so many to choose from.”
— Andrew Tanenbaum
s/standards/de facto implementations/
Milestones
2013: Two major C++11 language implementationsJune: GCC 4.8.1 and Clang 3.3
2014: Two major C++11 complete implementationsProbably early 2014: GCC 4.9 expected to join Clang 3.3+
2014-15: Multiple C++14 complete implementationsMy personal estimates, not official:• Clang: Releasing every 6-7 months (Jun/Dec), likely to make “14 in 14.”• GCC: Releasing every spring, 4.9 may not get all the way (?), but if not then
the next one seems likely to make “14 in just-past-14.”• VC++: No ETA yet (will keep you posted). Targeting whole “C++14 wave”
incl. Concepts.
“The nice thing about standards is that there are so many to choose from.”
— Andrew Tanenbaum
s/standards/de facto implementations/
“One C++”
Until 2013, the world had never enjoyed even one of the following, and we’ve still never had all three:
Until 2013, the world had never enjoyed even one of the following, and we’ve still never had all three:
Multiple consistent C++ products (never)with 100% conformance modulo bugs (first in 2013)in the same year the standard is published (never)
Multiple consistent C++ productswith 100% conformance modulo bugsin the same year the standard is published
Starting in 12-18mo, this could be the new normal
ObservationWe are
rapidly approachingOne C++