61
One C++ Herb Sutter

GN13 Sutter

Embed Size (px)

Citation preview

Page 1: GN13 Sutter

One C++

Herb Sutter

Page 2: GN13 Sutter

Themes: Understanding the C++ Tide

OrganizationMomentumPopulation shift (with just a little code)Trajectory

Page 3: GN13 Sutter

Visual C++ Roadmap Update

ISO C++ UpdatePortable C++ Libraries UpdateOne C++

Agenda

Page 4: GN13 Sutter

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

Page 5: GN13 Sutter

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

Page 6: GN13 Sutter

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

Page 7: GN13 Sutter

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

Page 8: GN13 Sutter

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

Page 9: GN13 Sutter

Visual C++ Roadmap UpdateISO C++ Update

Portable C++ Libraries UpdateOne C++

Agenda

Page 10: GN13 Sutter

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

Page 11: GN13 Sutter

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

Page 12: GN13 Sutter

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

Page 13: GN13 Sutter

Visual C++ Roadmap UpdateISO C++ UpdatePortable C++ Libraries Update

One C++

Agenda

Page 14: GN13 Sutter

C++11

C++98 + TR1C++11

Portable C++

C++98 C++98

language library

proxies for size comparisons: spec #pages, book #pagesGN’12

Page 15: GN13 Sutter

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

Page 16: GN13 Sutter

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

Page 17: GN13 Sutter

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

Page 18: GN13 Sutter

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

Page 19: GN13 Sutter

Wonderful! But… … where are we going to find all these libraries?

WG21PCL

GN’12

Page 20: GN13 Sutter

Portable C++ Librariesad-hoc

Page 21: GN13 Sutter

De Jure: The Standard

De jure librariesstd::HorizontalShip in the box

ad-hoc

Page 22: GN13 Sutter

Challenge

Make the world’s most flexible and efficient library-building language better for building libraries and bundle more broadly useful libraries

Page 23: GN13 Sutter

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

Page 24: GN13 Sutter

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

Page 25: GN13 Sutter

wg21core / ewg

lib / lewg

sg1sg8

sg4

3

……

……

Page 26: GN13 Sutter

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

---

---

--

----

-

---

Page 27: GN13 Sutter

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++

Page 28: GN13 Sutter

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.!

Page 29: GN13 Sutter

Reality check

Nobody knows what “most” C++ programmers do.

— Bjarne Stroustrup

Page 30: GN13 Sutter

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?

Page 31: GN13 Sutter

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

Page 32: GN13 Sutter

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

Page 33: GN13 Sutter

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

Page 34: GN13 Sutter

How Easy Is C++, Really?

// First thing Scott said:

cout << “Is that on a scale of 10 to 20?\n”

Page 35: GN13 Sutter

#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

Page 36: GN13 Sutter

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

Page 37: GN13 Sutter

#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

Page 38: GN13 Sutter

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%

Page 39: GN13 Sutter

Q: How many people here are developers?

Page 40: GN13 Sutter

Q2: How many of you brought a compiler?

Page 41: GN13 Sutter

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

Page 42: GN13 Sutter

Slide courtesy Rick Barraza

Page 43: GN13 Sutter

Slide courtesy Rick Barraza

Page 44: GN13 Sutter

Slide courtesy Rick Barraza

Page 45: GN13 Sutter

Slide courtesy Rick Barraza

Page 46: GN13 Sutter

Slide courtesy Rick Barraza

Page 47: GN13 Sutter

Slide courtesy Rick Barraza

Page 48: GN13 Sutter

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• …

Page 49: GN13 Sutter

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

Page 50: GN13 Sutter

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

Page 51: GN13 Sutter

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

Page 52: GN13 Sutter

Visual C++ Roadmap UpdateISO C++ UpdatePortable C++ Libraries UpdateOne C++

Agenda

Page 53: GN13 Sutter

Observation

The world has never had “One C++”

Page 54: GN13 Sutter

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++”

Page 55: GN13 Sutter

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++”

Page 56: GN13 Sutter

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

Page 57: GN13 Sutter

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++”

Page 58: GN13 Sutter

Until 2013, the world had never enjoyed even one of the following, and we’ve still never had all three:

Page 59: GN13 Sutter

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)

Page 60: GN13 Sutter

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

Page 61: GN13 Sutter

ObservationWe are

rapidly approachingOne C++