The road to C ++ 20

    imageToday ended the summer meeting of the ISO WG21 C ++ committee, held in Toronto from July 10 to 15. Soon we are likely to receive a detailed report from RG21 , and today, the esteemed public is invited to post- "warm up" with a discussion of the most interesting.

    The results of the meeting are as follows: the C ++ 17 standard is completed and will be published at the next meeting in November of this year; Standard C ++ 20 has already acquired the first major features done - concepts ( concepts ), explicit generalized lambda functions ( explicit generic lambdas ) - and this is just the beginning.

    The capabilities of the new C ++ 17 standard have been discussed more than once, they wrote about innovations on Habré , conducted reports at conferencestherefore I will not bring them here again. It's no secret that the key feature of this C ++ release was the transfer of the most “delicious” features to the uncertain future. Well, now it is safe to say that many of the long-awaited "features" moved to C ++ 20. The course taken to expand stdlib has not gone anywhere, so from C ++ 20 you can expect a much larger and rich set of functions.


    Draft C ++ 20 standard


    Concepts


    The long-suffering Concepts , once not included in C ++ 11, then redone as a new Concepts-Lite offer , are finally becoming part of the standard.

    The committee has not yet been able to agree on a brief syntax for concepts (terse syntax); however, discussion will continue within C ++ 20.

    _VA_OPT_


    #define LOG(msg, ...) printf(msg __VA_OPT__(,) __VA_ARGS__)
    LOG("hello world")   // => printf("hello world")
    LOG("hello world", ) // => printf("hello world")
    LOG("hello %d", n)   // => printf("hello %d", n)


    Explicit generic lambdas [pdf]


    []  (T t) { /* ... */ }

    Lambda functions were added to the language in the C ++ 11 standard, requiring a specific type; the C ++ 14 standard, in turn, allowed declaring the parameters of lambda functions with an auto type specifier:
    [](auto x) { /* ... */ }

    Now it will become easier to interact with parameter types (or parameters) - when defining lambda functions, you can use the familiar function template syntax:
    
    [](T x) { /* ... */ }
    [](T* p) { /* ... */ }
    [](T (&a)[N]) { /* ... */ }
    


    shared_ptr for arrays [pdf]


    shared_ptr p = make_shared(1024);

    The topic has been raised repeatedly - for example, here 1 .

    Byte ordering


    There is no more need to resort to tricky tricks - in fact, the compiler always knew the answer, just now he can share it:
    enum class endian
    {
      little = __ORDER_LITTLE_ENDIAN__,
      big    = __ORDER_BIG_ENDIAN__,
      native = __BYTE_ORDER__
    };


    Designated initializer [pdf]


    struct A { int x; int y; int z; }; A b{.x = 1, .z = 2};


    Default bit-field initializers


    struct S {int x : 8 = 42;};

    An innovation that has been expected since the in-class initialization in C ++ 11: now declarators for bitfield members support initialization.

    Fixed const-qualified member pointers


    struct X { void foo() const&; };
    X{}.foo();        // this is okay
    (X{}.*&X::foo)(); // ill-formed in C++17, well-formed in C++2a


    Improved template argument deduction


    vector v{vector{1, 2}};
     // Выведет vector вместо vector>


    TS (Technical Specifications)



    The TSs listed below are now part of C ++ 17 (already discussed last time):
    • Filesystem v1 [pdf] - port boost :: filesystem,
    • Parallelism v1 [pdf] - thanks to this TS, most of the algorithm library will now be available in the "parallel" version,
    • Library Fundamentals v1 [pdf] - extension of the standard library: std :: string_view, std :: optional, std :: any, system_error.


    In addition, the committee published the following technical specifications for which compilers can already make experimental implementations (and they are probably discussed here earlier):
    • Coroutines v1 - there were a lot of discussions around coroutines
    • Ranges v1 - slipped after the concepts, and, hopefully, will fall into C ++ 20
    • Networking v1 - has every chance of getting into C ++ 20; a socket library based on boost :: asio.

    The following are TS that are still under development.
    Some of them - but definitely not all - will be part of C ++ 20.

    Modules [pdf]


    Modules are still under development, however, a serious event happened in their life - an early draft of TS Modules became available . In its public version, nothing has changed over the past time (not counting a couple of small details) - i.e. modules are still based on Microsoft design and do not export macros. On this issue, I would like to hear the opinion of the committee members, since there are suspicions that this is not a final decision.

    Concurrency v1 [pdf]


    Published, they were going to accept at this meeting, but features at a different stage of readiness - so at the next meeting, this TS will be partially adopted in C ++ 20. Contains improvements that will make futures non-blocking (unlike std :: async), as well as latches, barriers and atomic smart pointers atomic_shared_ptr . I did not enter C ++ 17 due to the fact that it was published late and failed to collect enough practical experience.
    The implementation itself was inspired by MS Visual Studio, HPX and just :: thread. Before the meeting, there were fears that the new proposals P0676 and P0701 could postpone the adoption of TS indefinitely.

    Transactional Memory v1 [ pdf ]


    Published, however, on this TS, more recently, its authors still had questions regarding how fast atomics and shared_ptr can be outside of transactions if they should interact with the transaction. It remains to wait for clarification on whether something has changed since last time.

    Library fundamentals v2


    Published. Something auxiliary is required for C ++ 20.

    Executors v1 [pdf]


    In developing. Must enter C ++ 20, because several other TS libraries related to heterogeneous computing are tied to it.

    Reflection v1 [ pdf ]


    In developing. There is every chance of getting into C ++ 20, because one of the upcoming meetings will be dedicated to him.

    TS is based on code introspection and (more recently) materialization (reification). According to the committee, TS is useful in metaprogramming, which has become popular thanks to Boost :: Hana and similar libraries - as well as for heterogeneous containers .

    Concurrency v2


    In development at an early stage. Library of concurrent data structures, concurrent queues, lock-free algorithms and data structures; includes Hazard pointers (hazard pointers), RCU (safe memory release for lock-free containers), atomic views. The probability of getting into C ++ 20 is extremely small, because It is still at an early stage - while the committee is aware of the demand for this functionality and, according to the author, it is in the most active development.

    Parallelism v2


    In developing. It turns out that during the development of Parallelism v1, they did not only Parallel STL for the CPU, but also for the GPU. Parallelism v2 -

    Library fundamentals v3


    In developing.

    Contracts v1


    In developing. There will be either TS or inclusion in the C ++ 20 standard. In short: an improved version of assert that allows you to check pre- and post-conditions (i.e. invariants). According to the committee, the library will help C ++ become a safer language so that software developers for medicine, automobiles, aviation and cyber security sleep more peacefully.

    Numerics [ pdf ]


    In development at an early stage. Some of the advanced arithmetic will probably come in C ++ 20: decimal floating point, bounded types (e.g. fixed point types), unbounded types, multiprecision arithmetic. It should come in handy in the work of the game developers (who, however, are accustomed to write themselves what they need).

    2D Graphics v1


    At an early stage.

    On the little things


    Work is underway to add new functions to std :: string - starts_with , ends_with .

    It is worth noting that the reason for the appearance of several future TSs at once was distributed and heterogeneous computing. Committee members understand that for a long time, CUDA / OpenMP / OpenCL has overtaken native C ++. At the moment, all functions like std :: invoke, std :: async, parallel algorithms, etc., assume that std :: thread is used exclusively on the CPU; and even though the draft Executors TS draft contains progress on this front in the form of incorporating new features into it, this will not be enough, and there is still a lot of work to be done.

    For a long time, experts from Google, NVidia, Codeplay and NASDAQ have been participating in drafts of the upcoming TS to determine the direction of C ++ development, and you know the priorities of the future language: Concurrency, Parallelism, Transactional Memory, and Networking.

    Time will show that what is promised will really go into C ++ 20, and how much our hopes will be fulfilled.

    Literature


    As usual, I apologize for any inaccuracies made.
    Michael Wong - What's in C ++ 20 and the C ++ 17 final score card
    Discussion
    2017 Toronto ISO C ++ Committee Discussion Thread (Concepts in C ++ 20; Coroutines, Ranges and Networking TSes published)
    C ++ 17: The Language Features - Nicolai Josuttis
    Trip report: Summer ISO C ++ standards meeting (Toronto)

    Also popular now: