70
C++17: will it be great or just ok? Michael Wong Codeplay Software, VP of Research and Development ISOCPP.org Director, VP http://isocpp.org/wiki/faq/wg21#michael-wong Head of Delegation for C++ Standard for Canada Vice Chair of Programming Languages for Standards Council of Canada Past OpenMP CEO: http://openmp.org/wp/about-openmp/ Chair of WG21 SG5 Transactional Memory: https://groups.google.com/a/isocpp.org/forum/?hl=en&fromgroups#!forum/tm Chair of WG21 SG14 Games Dev/Low Latency/Financial Trading/Embedded: https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum/sg14 Editor: C++ SG5 Transactional Memory Technical Specification Editor: C++ SG1 Concurrency Technical Specification http:://wongmichael.com/about Post-Oulu C++ Standard meeting 2016

Michael Wong Codeplay Software, VP of Research and …+17post-oulu... · Michael Wong . Codeplay Software, VP of Research and Development . ... Past OpenMP CEO: ... Chair of WG21

Embed Size (px)

Citation preview

C++17: will it be great or just ok? Michael Wong

Codeplay Software, VP of Research and Development ISOCPP.org Director, VP http://isocpp.org/wiki/faq/wg21#michael-wong

Head of Delegation for C++ Standard for Canada

Vice Chair of Programming Languages for Standards Council of Canada Past OpenMP CEO: http://openmp.org/wp/about-openmp/

Chair of WG21 SG5 Transactional Memory: https://groups.google.com/a/isocpp.org/forum/?hl=en&fromgroups#!forum/tm

Chair of WG21 SG14 Games Dev/Low Latency/Financial Trading/Embedded: https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum/sg14

Editor: C++ SG5 Transactional Memory Technical Specification

Editor: C++ SG1 Concurrency Technical Specification

http:://wongmichael.com/about

Post-Oulu C++ Standard meeting 2016

© 2016 Codeplay Software Ltd. 2

Acknowledgement and Disclaimer • �Numerous people internal and external to the original C++/Khronos/OpenCL/SYCL group, in industry and academia, have made contributions, influenced ideas, written part of this presentations, and offered feedbacks to form part of this talk.

• �I even lifted this acknowledgement and disclaimer from some of them.

• �But I claim all credit for errors, and stupid mistakes. These are mine, all mine!

• �

© 2016 Codeplay Software Ltd. 3

Legal Disclaimer • �This work represents the view of the author and does not necessarily represent the view of Codeplay, IBM, Khronos, OpenMP, or ISOCPP.org.

• �Other company, product, and service names may be trademarks or service marks of others.

• This is part of an ongoing keynote presentation for upcoming C/C++ Standard status modified as C and C++ changes. Please attribute credit accordingly.

© 2016 Codeplay Software Ltd. 4

C++ Std Meeting at U of Toronto: 2017-07-10-15

4

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0369r0.pdf

The 2017 summer meeting of WG21 is being hosted at the University of Toronto, in Canada on July 10-15, 2017, Monday to Saturday (inclusive). The meeting will be held in the Bahen Centre for Information Technology at the University of Toronto (St. George Campus) in downtown Toronto.

© 2016 Codeplay Software Ltd. 5

Codeplay: world expert in Heterogeneous software platform for self-driving cars, AI/machine learning/neural networks, computer vision, data centres, graphics,

mobile devices, with Open Standards

Processors IP CPU, GPU, DSP, VPU, ViSP

Semiconductors

Module Integration

Algorithms

Software/Middleware Tools & layers to Standards

ISO 26262

LLVM

ISO C99/11 or C++ 11/14/17/20 compliant

Major Corporation

© 2016 Codeplay Software Ltd. 6

Codeplay products

+

Consumer

Automotive

Server/Cloud

Tablet IoT Robotics

Security Vision Smartphone

ADAS 360° Video Driver Monitoring

Self-Driving Cars Infotainment Agriculture

Big Data Analysis

Distributed Data

Adaptive Processors

Image Analysis Vision Processing

Machine Learning

© 2016 Codeplay Software Ltd. 7 7

Agenda

• Pop Quiz on C++11/C++14/C++17 lambdas • C++17 Goals (from Bjarne Stroustrup in May 2015) • C++17 Status • Compiler and Implementation status • Is it great or just ok?

© 2016 Codeplay Software Ltd. 8

Is this valid C++11/14 code today? class Work {

private: int value ; public: Work() : value(42) {} std::future spawn() { return std::async( [=,*this]()->int{ return value ; }); }

};

© 2016 Codeplay Software Ltd. 9

Generic Lambdas

• C++11

auto lambda = [](int x, int y) {return x + y;}

• C++14

auto lambda = [](auto x, auto y) {return x + y;}

9

© 2016 Codeplay Software Ltd. 10

Enter the Generic lambda

class __functor { };

[ captures ]

private: C *const __this; CaptureTypes __captures; public: __functor( C* this, CaptureTypes captures ) : __captures( captures ) { }

template<typename Ti > void operator()( Ti params) const->ret { statements; } // const C* const

Class C {

};

( auto params ) ->ret { statements; }

© 2016 Codeplay Software Ltd. 11

The “lambda” emoticon • C++03 struct functor

{

int &a;

functor(int& _a) : a(_a) { }

bool operator()(int x) const

{

return a == x;

}

};

int a = 42;

count_if(v.begin(), v.end(), functor(a));

• C++11

int a = 42; count_if(v.begin(), v.end(),

[&a](int x){ return x == a;});

• C++14 count_if(v.begin(),v.end(),[&a] (auto x){return x == a;});

11

© 2016 Codeplay Software Ltd. 12

Lambda gotchas with ‘this’ in C++11/14 one variable that can be captured without mentioning its name: this (pointer)

• This is invisible • Capture of members variables by

reference even if you wrote [=] • member variables cannot be

captured by value at all

struct S { int x ; void f() { // The following lambda captures are currently identical auto a = [&]() { x = 42 ; } // OK: transformed to (*this).x auto b = [=]() { x = 43 ; } // OK: transformed to (*this).x a(); assert( x == 42 ); b(); assert( x == 43 ); }

};

© 2016 Codeplay Software Ltd. 13

Lambdas == Functors inside of a class

( params )

class __functor { };

[ captures ]

private: C *const __this; CaptureTypes __captures; public: __functor( C* this, CaptureTypes captures ) : __captures( captures ) { }

auto operator() ( params ) const -> ret { statements; } // const C* const

Class C {

};

->ret { statements; }

© 2016 Codeplay Software Ltd. 14

C++17 Capture of *this

• C++14 work around [=,tmp=*this]

class Work { private: int value ; public: Work() : value(42) {} std::future spawn() { return std::async( [=,tmp=*this]()->int{ return tmp.value ; }); }

};

• C++17 class Work {

private: int value ; public: Work() : value(42) {} std::future spawn() { return std::async( [=,*this]()->int{ return value ; }); }

};

14

© 2016 Codeplay Software Ltd. 15 15

Agenda

• Pop Quiz on C++11/C++14/C++17 lambdas • C++17 Goals (from Bjarne Stroustrup in May 2015) • C++17 Status • Compiler and Implementation status • Is it great or just ok?

© 2016 Codeplay Software Ltd. 16

What is C++17? (N4492) Bjarne Stroustrup

Morgan Stanley, Columbia University www.Stroustrup.com

May 2015

C++17 Lenexa 16

© 2016 Codeplay Software Ltd. 17

What is C++17? • What’s the elevator pitch?

• We must have an answer

• It’s a major release • Like C++98 and C++11 • Not minor like C++03 and C++14

• If we deliver nothing major • The C++ community will be disappointed and angry • Other languages will benefit

• We must ship something coherent • A simple list of features is not good enough

C++17 Lenexa 17

© 2016 Codeplay Software Ltd. 18

Why bother? • Doesn’t everybody know that C++ is great? • No, just from last week

• “C++ is a bloated old language” • “Why can’t they let good enough alone?” • “We used D because C++ doesn’t have compile time functions” (GPSE paper) • “We built a library to help people coming from ordinary languages such as Haskell,

Python, and Ruby” (Columbia University class) • “Common knowledge” does not reflect industrial reality

• “academia” seems generally oblivious to modern C++ • We need an elevator pitch

• So, what is C++? • What is C++17?

C++17 Lenexa 18

© 2016 Codeplay Software Ltd. 19

High-level aims • Improve support for large-scale dependable software • Provide support for higher-level concurrency models • Simplify core language use, especially as it relates to the STL

and concurrency, and address major sources of errors. If I wanted to, I could see the last two aims as refinements of the first.

C++17 Lenexa 19

© 2016 Codeplay Software Ltd. 20

Dangers • Whatever we do, we should preserve C++’s fundamental

strengths: • A direct map to hardware (initially from C) • Zero-overhead abstraction (initially from Simula)

Depart from these and the language is no longer C++. • We must avoid the dual traps:

• Abandoning the past (e.g., by seriously breaking compatibility – C++ is heavily used for long-lasting systems)

• Failing to address newer challenges (e.g., by not supporting higher-level concurrency models – C++ is heavily used to address concurrency needs)

C++17 Lenexa 20

© 2016 Codeplay Software Ltd. 21

Don’t try to • Turn C++ into a radically different language • Turn parts of C++ into a much higher-level language by providing a

segregated sub-language • Have C++ compete with every other language by adding as many as

possible of their features • Incrementally modify C++ to support a whole new "paradigm" • Hamper C++'s use for the most demanding systems programming tasks • Increase the complexity of C++ use for the 99% for the benefit of the 1%

(us and our best friends) I think each of those would fail.

C++17 Lenexa 21

© 2016 Codeplay Software Ltd. 22

Improve support for large-scale dependable software

• Modules • to improve locality and improve compile time; n4465 and n4466

• Contracts • for improved specification; n4378 and n4415

• A type-safe union • probably functional-programming style pattern matching; something based on

my Urbana presentation, which relied on the Mach7 library: Yuriy Solodkyy, Gabriel Dos Reis and Bjarne Stroustrup: Open Pattern Matching for C++. ACM GPCE'13.

C++17 Lenexa 22

© 2016 Codeplay Software Ltd. 23

Provide support for higher-level concurrency models

• Basic networking • asio n4478

• A SIMD vector • to better utilize modern high-performance hardware; e.g., n4454 but I’d like a real vector rather

than just a way of writing parallelizable loops

• Improved futures • e.g., n3857 and n3865

• Co-routines • finally, again for the first time since 1990; N4402, N4403, and n4398

• Transactional memory • n4302

• Parallel algorithms (incl. parallel versions of some of the STL) • n4409

C++17 Lenexa 23

© 2016 Codeplay Software Ltd. 24

Simplify core language use and address major sources of errors • Concepts (n3701 and n4361)

• concepts in the standard library • based on the work done in Origin, The Palo Alto TR, and Ranges n4263, n4128 and n4382

• default comparisons • to complete the support for fundamental operations; n4475 and n4476

• uniform call syntax • among other things: it helps concepts and STL style library use; n4474

• operator dot • to finally get proxies and smart references; n4477

• array_view and string_view • better range checking, DMR wanted those: "fat pointers"; n4480

• arrays on the stack • "stack_array" anyone? But we need to find a safe way of dealing with stack overflow; n4294

• optional • unless it is subsumed by pattern matching, and I think not in time for C++17, n4480

C++17 Lenexa 24

© 2016 Codeplay Software Ltd. 25

Assumptions • I assume that C++17 will ship in 2017 • I didn’t segregate library components and language features

• That distinction is not meaningful for users. • The library and the language should work seamlessly together

• If your favorite feature isn't on my list • does it fit into the framework? • Should the list of aims be augmented?

• Not everything can be shipped in 2017 • TSs • C++20

C++17 Lenexa 25

© 2016 Codeplay Software Ltd. 26

My top 10 • Concepts (they allows us to precisely specify our generic programs and address the most vocal complaints about the quality

of error messages)

• Modules (provided they can demonstrate significant isolation from macros and a significant improvement in compile times)

• Ranges and other key STL components using concepts (to improve error messages for mainstream users and improved the precision of the library specification “STL2”)

• Uniform call syntax (to simplify the specification and use of template libraries)

• Co-routines (should be very fast and simple)

• Networking support (based on the asio in the TS)

• Contracts (not necessarily used in the C++17 library specification)

• SIMD vector and parallel algorithms (to better target modern hardware)

• Library “vocabulary types”, such as optional, variant, string_view, and array_view

• ???

What are your top ten?

C++17 Lenexa 26

© 2016 Codeplay Software Ltd. 27

How? • We are volunteers

• No “you must do that” • No “you may not work on that”

• I don’t suggest process changes • Feel free to try • I encourage that we focus on something • I suggested a list of issues to focus on to simulate discussion • I don’t propose that we spend time constructing an official detailed list

• I suggest • We deliver something significant in 2017 • We articulate what it is we deliver (in advance)

After that, C++20 will be there to “complete C++17”

• just as C++14 completed C++11.

C++17 Lenexa 27

© 2016 Codeplay Software Ltd. 28

What if WG decides to do far less? • That is, C++17 become a minor release with some TSs

• Can one TS rely on another?

• Scenario1:

• Fragmentation

• Scenario2: • Industry consortium

• Scenario3: • Apathy

C++17 Lenexa 28

© 2016 Codeplay Software Ltd. 29

Don’t • Make something a library because that's easier to get accepted in the committee than a language feature (even if there is good

argument that what is provided is fundamental) • Provide an isolated feature because integration with existing features would cause work on compatibility issues. This just postpones

integration until later • Given a choice between two alternatives, choose both, add a third, and modify the first two "to please everybody who could affect

the vote" (this is pure design-by- committee) • Oppose proposals seen as competing with your favorite proposal for time/resources • Push hard for the immediately useful (only) • Oppose proposals not relevant to your current job, stalling an improvement that would benefit others • Focus on the Working Paper (WP) text and choose among technical alternatives based on what fits best with the current text, rather

than giving precedence to user needs • Think that more syntax equates to safety and ease of use for the majority of programmers • Serve the library writers and other experts while ignoring the majority of current and potential C++ programmers • Chase “current fashion” and push for features from other popular languages without considering their impact on C++ programming

styles or interactions with existing C++ facilities • Try to make a proposal self-contained to avoid interaction with existing facilities • Ignore other proposals being considered • Present “principles” as non-negotiable absolutes • Accept nothing that is not perfect • Try to do “everything”

C++17 Lenexa 29

© 2016 Codeplay Software Ltd. 30 30

Agenda

• Pop Quiz on C++11/C++14/C++17 lambdas • C++17 Goals (from Bjarne Stroustrup in May 2015) • C++17 Status • Compiler and Implementation status • Is it great or just ok?

© 2016 Codeplay Software Ltd. 31

Status of Language Standards as of 1H 2016 C11 ratified Dec 2011,

• Plan to published a bug fixeTC in the next few years: C17?

• starting work on next C for C 22, major release

C++14 ratified Dec 2014, a minor fix release on C++11

C++17 features closed June 2016 (Oulu) • July 2016-March 2017: 2 rounds of National Body comments on 2 CDs at 2 F2F meetings (Seattle, Kona) • March 2017: Issue Final National Body Comment Vote to approve a DIS after Kona • July 2017: Collate vote and Ratify in Toronto C++ Std meeting by committee and send to Geneva

• Unless we don’t get agreement in Toronto from the vote after Kona, then we have to issue an FDIS

After C++17 • Was supposed to be every 3 years, so C++20, 23, …

Slide 31 of 8

© 2016 Codeplay Software Ltd. 32

Sum of all things C11 ,C++11, & C++14

32

Rvalue Reference

static_assert

Template aliases

Extern template

Variadic Templates

Strongly Typed Enums

Forward Declaration of Enums

Extended friend Declarations

Generalized Constant Expressions

variadic macros, empty macro argument,

concatenation of mixed char and wchar literals

Alignment

long long

extended integer types

Delegating Constructors

char16_t,char32_t

Right Angle Brackets

Auto type inference

New function declaration syntax

__func__

PODs unstrung

Propagating exceptions

Decltype

Extending sizeof

Defaulted and Deleted Functions

Lambda

nullptr

Inheriting Constructors

Explicit Conversion Operators

Raw.unicode String Literals

Universal Character Names in Literals

Namespace Association

Unrestricted Unions

Atomic operations

memory model

Multi-threading Library

Unicode Strings UTF8 Literals

type_trait names

Local Classes more Useful

Generic lambdas

Thread-Local Storage

Data-Dependency Ordering

Dynamic initialization and concurrency

Garbage Collection

SFINAE problem for expressions

Member Initializers

range-based for-loop

General Attributes

User-defined Literals

Explicit Virtual Overrides

unique_ptr,forward_list,

random numbers

hash tables

generalized functors

tuples

hash tables,

regular expressions

enhanced binder

enhanced member pointer adapter

Tweak to certain C++ contextual conversions

Binary literals

decltype(auto) Return type deduction for normal functions

Initialized lambda captures

Variable templates

Relaxing requirements on constexpr functions

Member initializers and aggregates Clarifying memory allocation

[[deprecated]] attribute

Single quotation mark as digit separator C++ Sized Deallocation

© 2016 Codeplay Software Ltd. 33

C++11 land: http://fearlesscoder.blogspot.ca/2012/01/c11-lands.html

33

© 2016 Codeplay Software Ltd. 34

Structure of C++ Standard Committee

© 2016 Codeplay Software Ltd. 35

C++14, C++17, 8 TS’s (View from early 2015)

IBM 35

© 2016 Codeplay Software Ltd. 36

C++ Std Timeline

36

© 2016 Codeplay Software Ltd. 37

Pre-C++11 projects ISO number Name Status What is it? C++17?

ISO/IEC TR 18015:2006 Technical Report on C++ Performance

Published 2006 (ISO store) Draft: TR18015 (2006-02-15)

C++ Performance report No

ISO/IEC TR 19768:2007 Technical Report on C++ Library Extensions

Published 2007-11-15 (ISO store) Draft: n1745 (2005-01-17) TR 29124 split off, the rest merged into C++11

Has 14 Boost libraries, 13 of which was added to C++11.

N/A (mostly already included into C++11)

ISO/IEC TR 29124:2010

Extensions to the C++ Library to support mathematical special functions

Published 2010-09-03 (ISO Store) Final draft: n3060 (2010-03-06). Under consideration to merge into C++17 by p0226 (2016-02-10)

Really, ORDINARY math today with a Boost and Dinkumware Implementation

YES

ISO/IEC TR 24733:2011

Extensions for the programming language C++ to support decimal floating-point arithmetic

Published 2011-10-25 (ISO Store) Draft: n2849 (2009-03-06) May be superseded by a future Decimal TS or merged into C++ by n3871

Decimal Floating Point decimal32 decimal64 decimal128

No. Ongoing work in SG6

© 2016 Codeplay Software Ltd. 38

Status after June Oulu C++ Meeting

ISO number Name Status links C++17?

ISO/IEC TS 18822:2015 C++ File System Technical Specification

Published 2015-06-18. (ISO store). Final draft: n4100 (2014-07-04)

Standardize Linux and Windows file system interface

YES

ISO/IEC TS 19570:2015 C++ Extensions for Parallelism

Published 2015-06-24. (ISO Store). Final draft: n4507 (2015-05-05)

Parallel STL algorithms.

YES but removed dynamic execution policy, exception_lists, changed some names

ISO/IEC TS 19841:2015 Transactional Memory TS Published 2015-09-16, (ISO Store). Final draft: n4514 (2015-05-08)

Composable lock-free programming that scales

No. Already in GCC 6 release and waiting for subsequent usage experience.

ISO/IEC TS 19568:2015 C++ Extensions for Library Fundamentals

Published 2015-09-30, (ISO Store). Final draft: n4480 (2015-04-07)

optional, any, string_view and more

YES but moved Invocation Traits and Polymorphic allocators into LF TS2

ISO/IEC TS 19217:2015 C++ Extensions for Concepts

Published 2015-11-13. (ISO Store). Final draft: n4553 (2015-10-02)

Constrained templates

No. Already in GCC 6 release and and waiting for subsequent usage experience.

© 2016 Codeplay Software Ltd. 39

Status after June Oulu C++ Meeting ISO number Name Status What is it? C++17?

ISO/IEC TS 19571:2016 C++ Extensions for Concurrency

Published 2016-01-19. (ISO Store) Final draft: p0159r0 (2015-10-22)

improvements to future, latches and barriers, atomic smart pointers

No. Already in Visual Studio release and waiting for subsequent usage experience.

ISO/IEC DTS 19568:xxxx C++ Extensions for Library Fundamentals, Version 2

DTS. Draft: n4564 (2015-11-05)

source code information capture and various utilities

No. Resolution of comments from national standards bodies in progress

ISO/IEC DTS 21425:xxxx Ranges TS In development, Draft n4569 (2016-02-15)

Range-based algorithms and views

No. Wording review of the spec in progress

ISO/IEC DTS 19216:xxxx Networking TS In development, Draft n4575 (2016-02-15)

Sockets library based on Boost.ASIO

No. Wording review of the spec in progress.

Modules

In development, Draft p0142r0 (2016-02-15) and p0143r1 (2016-02-15)

A component system to supersede the textual header file inclusion model

No. Initial TS wording reflects Microsoft’s design; changes proposed by Clang implementers expected.

© 2016 Codeplay Software Ltd. 40

Status after June Oulu C++ Meeting ISO number Name Status What is it? C++17?

Numerics TS Early development. Draft p0101 (2015-09-27) Various numerical facilities No. Under active

development

ISO/IEC DTS 19571:xxxx Concurrency TS 2 Early development

Exploring executors, synchronic types, lock-free, atomic views, concurrent data structures

No. Under active development

ISO/IEC DTS 19570:xxxx Parallelism TS 2 Early development. Draft n4578 (2016-02-22)

Exploring task blocks, progress guarantees, SIMD.

No. Under active development

ISO/IEC DTS 19841:xxxx Transactional Memory TS 2 Early development Exploring on_commit, in_transaction.

No. Under active development.

Graphics TS Early development. Draft p0267r0 (2016-02-12) 2D drawing API No. Wording review of the

spec in progress

ISO/IEC DTS 19569:xxxx Array Extensions TS Under overhaul. Abandoned draft: n3820 (2013-10-10)

Stack arrays whose size is not known at compile time

No. Withdrawn; any future proposals will target a different vehicle

© 2016 Codeplay Software Ltd. 41

Status after June Oulu C++ Meeting

ISO number Name Status What is it? C++17?

Coroutine TS

Initial TS wording will reflect Microsoft’s await design; changes proposed by others expected.

Resumable functions No. Under active development

Reflection TS Design direction for introspection chosen; likely to target a future TS

Code introspection and (later) reification mechanisms No. Under active development

Contracts TS Unified proposal reviewed favourably. )

Preconditions, postconditions, etc. No. Under active development

Massive Parallelism TS Early development Massive parallelism dispatch No. Under active development.

Heterogeneous Device TS Early development. Support Hetereogeneous Devices

No. Under active development.

C++17 On track for 2017

Filesystem TS, Parallelism TS, Library Fundamentals TS I, if constexpr, and various other enhancements are in. See slide 44-47 for details.

YES

© 2016 Codeplay Software Ltd. 42

Library Fundamental TS 1: what made it and what got moved to TS3

Feature Sections Notes Implementations C++17

apply() 3.2.2 gcc YES

Variable Templates For Type Traits 3.3.1 Already added to C++17 N/A

Invocation type traits 3.3.2 None? NO

optional 5 gcc YES

any 6 gcc YES

string_view 7 gcc YES

shared_ptr with array support 8.2 gcc YES

polymorphic memory resources (PMRs) 8.4, 2.1, 4.2, 9.2, 9.3 gcc (partial) NO

search 4.3, 10.2 gcc YES

shuffle 10.3 gcc YES

© 2016 Codeplay Software Ltd. 43

Library Fundamental TS 2: being reviewed • Source-code information capture (really a Reflection feature with a library interface) • A generalized callable negator • Uniform container erasure • GCD and LCM functions (GCD/LCM moved into C++17) • Delimited iterators • observer_ptr, the world’s dumbest smart pointer • A const-propagating wrapper class • make_array • A metaprogramming utility dubbed the “C++ detection idiom” • A replacement for std::rand() • Logical type traits.

© 2016 Codeplay Software Ltd. 44

•static_assert(condition) without a message •Allowing auto var{expr}; •Writing a template template parameter as template <…> typename Name

•Removing trigraphs •Folding expressions •std::uncaught_exceptions() •Attributes for namespaces and enumerators •Shorthand syntax for nested namespace definitions •u8 character literals •Allowing full constant expressions in non-type template parameters

•Removing the register keyword, while keeping it reserved for future use

•Removing operator++ for bool •Making exception specifications part of the type system. •__has_include(), •Choosing an official name for what are commonly called “non-static data member initializers” or NSDMIs. The official name is “default member initializers”.

•A minor change to the semantics of inheriting constructors

• The [[fallthrough]] attribute,

• The [[nodiscard]] attribute,

• The [[maybe_unused]] attribute

• Extending aggregate initialization to allow initializing base subobjects.

• Lambdas in constexpr contexts

• Disallowing unary folds of some operators over an empty parameter pack

• Generalizing the range-based for loop

• Lambda capture of *this by value • Relaxing the initialization rules for scoped

enum types.

• Hexadecimal floating-point literals

C++ 17 Language features already voted in

© 2016 Codeplay Software Ltd. 45

if constexpr (formerly known as constexpr_if, and before that, static_if)

Template parameter deduction for constructors

template <auto N>

Inline variables

Guaranteed copy elision

Guarantees on expression evaluation order

Dynamic memory allocation for over-aligned data

is_contiguous_layout (really a library feature, but it needs compiler support)

Removing exception specifications

Using attribute namespaces without repetition

Replacement of class objects containing reference members

Standard and non-standard attributes

Forward progress guarantees: Base definitions

Forward progress guarantees for the Parallelism TS features

• Introducing the term 'templated entity‘

• Proposed wording for structured bindings

• Selection statements with initializer • Explicit default constructors and copy-

list-initialization • Not in C++17 (yet!)

• Default comparisons • For/against/neutral: 16/31/20

• Operator dot • Not moved as CWG discovered a flaw

C++17 Language features voted in Oulu Finland

© 2016 Codeplay Software Ltd. 46

•Removing some legacy library components

•Contiguous iterators

•Safe conversions in unique_ptr<T[]>

•Making std::reference_wrapper trivially copyable

•Cleaning up noexcept in containers

•Improved insertion interface for unique-key maps

•void_t alias template

•invoke function template

•Non-member size(), empty(), and data() functions

•Improvements to pair and tuple

•bool_constant

•shared_mutex

•Incomplete type support for standard containers

•Type traits variable templates.

•as_const()

•Removing deprecated iostreams aliases

•Making std::owner_less more flexible

•Polishing <chrono>

•Variadic lock_guard

•Logical type traits.

• Re-enabling shared_from_this

• not_fn

• constexpr atomic::is_always_lock_free

• Nothrow-swappable traits

• Fixing a design mistake in the searchers interface

• An algorithm to clamp a value between a pair of boundary values

• constexpr std::hardware_{constructive,destructive}_interference_size

• A 3-argument overload of std::hypot

• Adding constexpr modifiers

• Giving std::string a non-const data() member function

• is_callable, the missing INVOKE-related trait

C++17 Library features already voted in

© 2016 Codeplay Software Ltd. 47

•High-performance, locale-independent number <-> string conversions •make_from_tuple() (like apply(), but for constructors) •Letting folks define a default_order<> without defining std::less<> •Splicing between associative containers •Relative paths •C11 libraries •shared_ptr::weak_type •gcd() and lcm() from LF TS 2 •Deprecating std::iterator, redundant members of std::allocator, and is_literal •Reserve a namespace for STL v2 •std::variant<> •Better Names for Parallel Execution Policies in C++17 •Temporarily discourage memory_order_consume •A <random> Nomenclature Tweak

• Synopses for the C library

• Making Optional Greater Equal Again

• Making Variant Greater Equal

• Homogeneous interface for variant, any and optional

• Elementary string conversions

• Integrating std::string_view and std::string

• has_unique_object_representations

• Extending memory management tools

• Emplace Return Type

• Removing Allocator Support in std::function

• make_from_tuple: apply for construction

• Delete operator= for polymorphic_allocator

• Fixes for not_fn

• Adapting string_view by filesystem paths

• Hotel Parallelifornia: terminate() for Parallel Algorithms Exception Handling

C++17 Library features voted in Oulu Finland

© 2016 Codeplay Software Ltd. 48

SG1 Par/Con TS

SG5 Transactional Memory TS

SG14 Low Latency

3

… …

The Parallel and concurrency planets of C++ today

© 2016 Codeplay Software Ltd. 49

C++1Y(1Y=17/20/22) SG1/SG5/SG14 Plan red=C++17, blue=C++20? Black=future?

Parallelism • Parallel Algorithms: • Data-Based Parallelism.

(Vector, SIMD, ...) • Task-based parallelism

(cilk, OpenMP, fork-join) • Execution Agents • Progress guarantees • MapReduce • Pipelines

Concurrency • Future++ (then, wait_any, wait_all): • Executors: • Resumable Functions, await (with

futures) • Lock free techniques/Transactions • Synchronics • Atomic Views • Co-routines • Counters/Queues • Concurrent Vector/Unordered Associative

Containers • Latches and Barriers • upgrade_lock • Atomic smart pointers

© 2016 Codeplay Software Ltd. 50

Execution Policies for C++17 with some name change

using namespace std::experimental::parallelism; std::vector<int> vec = ... // previous standard sequential sort std::sort(vec.begin(), vec.end()); // explicitly sequential sort; changed seq to ser std::sort(std::ser, vec.begin(), vec.end()); // permitting parallel execution std::sort(std::par, vec.begin(), vec.end()); // permitting vectorization; changed par_vec to par_unseq std::sort(std::par_unseq, vec.begin(), vec.end());

© 2016 Codeplay Software Ltd. 51

Life cycle of C++ proposals

© 2016 Codeplay Software Ltd. 52

From “cool” idea to “international standard” 0. Cool idea posted to a blog, mailing list, Reddit, etc. (Most proposals never make it past this stage.)

1. Proposer submits an initial design paper, and asks to present it to the design group. Paper includes motivation, alternatives considered, concrete examples, and a specific proposal in sufficient detail to evaluate.

2. Design group agrees they are interested in this area and pursuing exploration of this general feature, and asks for revisions. (A standalone proposal is usually iterated on at multiple meetings to refine the design. If there are competing proposals, the iteration and convergence takes longer. If there is a lot of iteration required and work can be done at additional face-to-face or telecon meetings between meetings, the design group chair may recommend starting a Study Group for the topic to produce a merged initial proposal to bring back to the design group.)

3. Design group agrees to pursue a specific refined design direction, and asks for initial wording.

4. Design group approves the initial wording, and forwards to wording group.

5. Wording group reviews and refines wording, agrees it’s ready to be included in a working draft, and forwards it to the full committee.

6. The full committee agrees to adopt the wording into a working draft, and creates an issues list to track issues. (If the work is to be put in its own TS, this would be an initial working draft for a new TS.)

7. Design and wording groups process design and wording issues to refine the specification, and forward each change for approval by the full committee. (The wording must correctly express the approved design; any questions about what specific code examples are supposed to mean must be resolved in design and be reflected in wording; the wording must be clear so that implementers know what to implement, and that programmers can write portable code that works the same way on different implementations.)

8. The full committee sends the working draft out for international comment ballot beyond the committee, and a few months later ballot comments are forwarded back to the committee.

9. Design and wording groups resolve ballot comments, and forward each change for approval by the full committee.

10. The full committee sends the working draft out for its final approval ballot and/or publication.

11. If the proposal is first published in a TS, then after getting beta feedback (usually including experience with a vendor implementing the feature and users trying out the implementation) someone will propose adopting it into the IS working draft, possibly with changes based on usage feedback, and after design and wording stability evaluation in the design and wording groups, repeat Stages 6-10 to “IS quality” (usually much faster than the first time since typically most of the work was done in the TS).

Modules

Ranges, Networking, LF

TS3, Parallelism TS2

Contracts, coroutines, 2D Graphics

LF TS2 Concepts, TM, Concurrency

© 2016 Codeplay Software Ltd. 53

C++ Language and Library TS • Programming Language C++ IS: Richard Smith. This is the main C++ Standard project. N3797

• File System TS: Beman Dawes. Work based on Boost.Filesystem v3, including file and directory iteration. N3790

• Library Fundamentals TS 1: Jeffrey Yasskin. A set of standard library extensions for vocabulary types like optional<> and other fundamental utilities. N3848

• Concepts TS: Andrew Sutton. Extensions for template type checking.

• Parallelism TS 1: Jared Hoberock. Initially includes a Parallel STL library with support for parallel algorithms to exploit multiple cores, and vectorizable algorithms to exploit CPU and other vector units.

• Concurrency TS 1: Artur Laksberg. Initially includes library support for non-blocking extensions to std::future, atomic shared ptrs, latches & barriers.

• Transactional Memory TS 1: Michael Wong. A promising way to deal with mutable shared memory, that is expected to be more usable and scalable than current techniques based on atomics and mutexes.

• Library Fundamentals TS 2: Geoffrey Romer. A set of standard library extensions.

• Networking TS: Jonathan Wakely. A small set of network-related libraries including support for network byte order transformation and URIs.

• Ranges TS: Casey Carter. Initially includes concept-based range versions of STL iterators and algorithms.

• Modules TS: Gabriel Dos Reis. An alternative to the header inclusion-based build model.

• Concurrency TS 2: Michael Wong. Initially includes library support for executors and lock-free techniques. Additionally may include language extensions like coroutines, and additional libraries such as concurrent hash containers and latches.

IBM 53

© 2016 Codeplay Software Ltd. 54 54

Agenda

• Pop Quiz on C++11/C++14/C++17 lambdas • C++17 Goals (from Bjarne Stroustrup in May 2015) • C++17 Status • Compiler and Implementation status • Is it great or just ok?

© 2016 Codeplay Software Ltd. 55

GCC C++17 status Language Feature Proposal Available in GCC? SD-6 Feature Test Removing trigraphs N4086 5.1 u8 character literals N4267 6 __cpp_unicode_characters >= 201411 Folding expressions N4295 6 __cpp_fold_expressions >= 201411

Attributes for namespaces and enumerators N4266 4.9 (namespaces) 6 (enumerators)

__cpp_namespace_attributes >= 201411 __cpp_enumerator_attributes >= 201411

Nested namespace definitions N4230 6 __cpp_nested_namespace_definitions >= 201411

Allow constant evaluation for all non-type template arguments N4268 6 __cpp_nontype_template_args >= 201411

Extending static_assert N3928 6 __cpp_static_assert >= 201411 [[fallthrough]] attribute P0188R1 N/A (no fallthrough warning) __has_cpp_attribute(fallthrough) [[nodiscard]] attribute P0189R1 [[gnu::warn_unused_result]] __has_cpp_attribute(nodiscard) [[maybe_unused]] attribute P0212R1 [[gnu::unused]] __has_cpp_attribute(maybe_unused)

Extension to aggregate initialization P0017R1 No __cpp_aggregate_bases >= 201603

Wording for constexpr lambda P0170R1 No __cpp_constexpr >= 201603

Unary Folds and Empty Parameter Packs P0036R0 6 __cpp_fold_expressions >= 201603

Generalizing the Range-Based For Loop P0184R0 6 __cpp_range_based_for >= 201603

Lambda capture of *this by Value P0018R3 No __cpp_capture_star_this >= 201603

Construction Rules for enum class variables P0138R2 No

Hexadecimal floating literals for C++ P0245R1 3.0 __cpp_hex_float >= 201603

© 2016 Codeplay Software Ltd. 56

GCC TS and SD status Document Latest draft Available in GCC? Options and Feature

Test Macro

SD-6: SG10 feature test recommendations SD-6

Yes

[TS] Concepts N4377 GCC 6 -fconcepts __cpp_concepts >= 201507

[TS] Library Fundamentals, Version 1 (invocation type traits) N4480 No

[DRAFT TS] Library Fundamentals, Version 2 (source_location) N4529 No

[TS] Modules P0143R2 No

[TS] Transactional Memory N4514 GCC 6 (no atomic_cancel) –fgnu-tm

__cpp_transactional_memory >= 201505

© 2016 Codeplay Software Ltd. 57

Clang C++17 status Language Feature C++1z Proposal Available in Clang?

static_assert with no message N3928 Clang 3.5 Disabling trigraph expansion by default N4086 Clang 3.5 typename in a template template parameter N4051 Clang 3.5

New auto rules for direct-list-initialization N3922 Clang 3.8 (8)

Fold expressions N4295 Clang 3.6 P0036R0 SVN

u8 character literals N4267 Clang 3.6 Nested namespace definition N4230 Clang 3.6 Attributes for namespaces and enumerators N4266 Clang 3.6

Allow constant evaluation for all non-type template arguments N4268 Clang 3.6

Remove deprecated register storage class P0001R1 Clang 3.8 Remove deprecated bool increment P0002R1 Clang 3.8 Make exception specifications part of the type system P0012R1 No

__has_include in preprocessor conditionals P0061R1 Yes

New specification for inheriting constructors (DR1941 et al) P0136R1 No

[[fallthrough]] attribute P0188R1 SVN [[nodiscard]] attribute P0189R1 SVN [[maybe_unused]] attribute P0212R1 SVN

Aggregate initialization of classes with base classes P0017R1 SVN

constexpr lambda expressions P0170R1 No Differing begin and end types in range-based for P0184R0 SVN Lambda capture of *this P0018R3 SVN Direct-list-initialization of enums P0138R2 SVN Hexadecimal floating-point literals P0245R1 Yes

© 2016 Codeplay Software Ltd. 58

Clang TS and SD status Document Latest draft Available in Clang?

SD-6: SG10 feature test recommendations SD-6

Clang 3.4 (N3745)

Clang 3.6 (N4200) [TS] Concepts P0121R0 No

[TS] Library Fundamentals, Version 1 (invocation type traits) N4480 No

[DRAFT TS] Library Fundamentals, Version 2 (source_location)

N4529 No

[TS] Modules P0143R2 No

[TS] Transactional Memory N4514 No

© 2016 Codeplay Software Ltd. 59 59

Agenda

• Pop Quiz on C++11/C++14/C++17 lambdas • C++17 Goals (from Bjarne Stroustrup in May 2015) • C++17 Status • Compiler and Implementation status • Is it great or just ok?

© 2016 Codeplay Software Ltd. 60

Future C++ Standard schedules • After June, Oulu Finland

• Instructed Convenern to send feature complete C++17 Commiteee Draft (CD) for National Body comment

• Address returned comments in November Issaquah, • Possible, but unlikely to Issue Draft International Standard (DIS) after Issaquah only if we can

address all comments • Feb Kona meeting address remaining comments • Likely Issue DIS after Kona, Feb 2017, send it to National Body for final approval ballot; this is

just an up/down vote, no comments • Most likely approved, then celebrate in July 2017 Toronto Meeting • Then send it to ISO Geneva for publication, likely by EOY 2017

• After C++17 • Default is 3 yr cycle: C++20, 23

© 2016 Codeplay Software Ltd. 61

2017 2013 2014 2015 2016 2017

C++14 Ratify 5/31/2014

Clang 3.5 Release 8/31/2014

C++14 Implemented in Clang 3.5 9/3/2014

C++14 Released 12/31/2014

C++17 Implemented in Clang 4.0? 2/28/2017

C++17 Ratify? 5/31/2017

C++17 Release? 12/31/2017

Clang 3.6 Release 2/28/2015

Clang 3.7 Release

8/31/2015

Clang 3.9 Release? 8/31/2016

Clang 4.0 Release?

2/28/2017

The future of clang releases compared to C++ Std

Clang 3.8 Release

2/29/2016

© 2016 Codeplay Software Ltd. 62

Improve support for large-scale dependable software

• Modules • to improve locality and improve compile time; n4465 and n4466

• Contracts • for improved specification; n4378 and n4415

• A type-safe union • probably functional-programming style pattern matching; something based on

my Urbana presentation, which relied on the Mach7 library: Yuriy Solodkyy, Gabriel Dos Reis and Bjarne Stroustrup: Open Pattern Matching for C++. ACM GPCE'13.

C++17 Lenexa 62

© 2016 Codeplay Software Ltd. 63

Provide support for higher-level concurrency models

• Basic networking • asio n4478

• A SIMD vector • to better utilize modern high-performance hardware; e.g., n4454 but I’d like a real vector rather than just a way

of writing parallelizable loops

• Improved futures • e.g., n3857 and n3865

• Co-routines • finally, again for the first time since 1990; N4402, N4403, and n4398

• Transactional memory • n4302

• Parallel algorithms (incl. parallel versions of some of the STL • n4409

C++17 Lenexa 63

© 2016 Codeplay Software Ltd. 64

Simplify core language use and address major sources of errors • Concepts (n3701 and n4361)

• concepts in the standard library • based on the work done in Origin, The Palo Alto TR, and Ranges n4263, n4128 and n4382

• default comparisons • to complete the support for fundamental operations; n4475 and n4476

• uniform call syntax • among other things: it helps concepts and STL style library use; n4474

• operator dot • to finally get proxies and smart references; n4477

• array_view and string_view • better range checking, DMR wanted those: "fat pointers"; n4480

• arrays on the stack • "stack_array" anyone? But we need to find a safe way of dealing with stack overflow; n4294

• optional • unless it is subsumed by pattern matching, and I think not in time for C++17, n4480

C++17 Lenexa 64

May come back in limited form with

National Body comment

May come back in limited form with

National Body comment

© 2016 Codeplay Software Ltd. 65

•You blew it •Not a Major release •No risk, no gain •Nobody implement TSs •Tethering tower of Babel of TSs

• Did a nice job • But not Minor either • Safe and conservative wins • TSs are implemented • Followed the rules of a bus

train model, how to get 110 people to work together

The Verdict on C++17? (from reddit)

A Medium/OK Release

© 2016 Codeplay Software Ltd. 66

Parting thoughts as to why C++17 is not Major

• “When a language is as successful as C++ and Java, with millions of users, the effort appropriate to minimize risk to users becomes more important. That is why it is more important for significant new features to go through a thorough TS process now than it was in the earlier days of C++.”

© 2016 Codeplay Software Ltd. 67

Parting thoughts as to why C++17 missed the boat

• “… the committee has become to risk adverse and even though shipping all the major features in the pipeline is infeasible in the short term, shipping none is (again IMO) a bad mistake. C++11 and C++14 built up a momentum, that we should maintain. We need something for the enthusiasts to present as well as something for the established users to use.”

© 2016 Codeplay Software Ltd. 68

Conclusion “C++17 will change the way we write C++ code, just as C++11

and C++14 did. For example, string_view and optional are expected to be heavily used in writing interfaces. And with parallel STL often you can just add std::par or std::par_unseq, and your algorithm will speed up by a factor of 2-4 on ordinary hardware; we had a compelling story with C++11 move semantics where we could say “just recompile your code and it’ll often be noticeably faster,” and this is likely to be an even bigger improvement.”

© 2016 Codeplay Software Ltd. 69

sycl.tech

69

@codeplaysoft codeplay.com

[email protected]