C ++ 20 is getting closer. Jacksonville meeting

    In early March, the meeting of the international working group WG21 on standardization C ++ ended in the American city of Jacksonville. At the meeting, we added chips in C ++ 20, prepared for the release of a “preview” of new components, and polished them to the brilliance of the roughness of the tongue.

    Want to look at the news and find out:

    • Why is there a gold medal on the right?
    • How's the cross-platform SIMD doing?
    • What will happen if 4000 is divided by the last Friday of February?
    • What are the pitfalls of coroutines?
    • What cool chips for multi-threaded programming will be available soon?

    Calendars and time zones

    See how beautifully and easily dates can now be set in C ++ 20:

    using std::chrono;
    year_month_day ymd = 2016y/May/29d; // 2016-05-29

    Need to work with milliseconds, and even in the time zone of Tokyo? No problem:

    auto tp = sys_days{ymd} + 7h + 30min + 6s + 153ms; // 2016-05-29 07:30:06.153 UTC
    zoned_time zt = {"Asia/Tokyo", tp};
    cout << zt << '\n';                                          // 2016-05-29 16:30:06.153 JST

    There are tools for working with international atomic time, parsing times from a string, exotic data types that allow you to store the dates “second Friday of February”, “second week” or “second week of March”. etc.

    So now you can get the date of the last Friday of February 4000:

    auto last_friday_feb = February/Friday[last];
    std::cout << 4000 / last_friday_feb << std::endl;

    A rough description of all the features is available here .


    If you like std :: string_view from C ++ 17 (or boost :: string_view / boost :: string_ref), then you will especially like std :: span!

    Imagine you have a template function doing something with an int array:

    void do_something(int* p, size_t size);

    To call this method you need to write a lot:

    std::vector v;
    do_something(v.data(), v.size());
    int data[1024];
    do_something(data, std::size(data));
    boost::container::small_vector sm;
    do_something(sm.data(), sm.size());

    Another minus is that inside such a method it is inconvenient to work with the algorithms of the standard library + range based for will not work:

    void do_something(int* p, size_t size) {
        std::sort(p, p + size);
        for (size_t i = 0; i < size; ++i) {
            p[i] += p[0];

    So, std :: span is a class that stores the pointer and the size of the data array (while the size is sometimes not stored, but the information available at the compilation stage is used). With this new class, the code becomes somewhat simpler and without pointers:

    void do_something(std::span p) {
        for (int& v: p) {
            v += p[0];
    // ...
    std::vector v;
    int data[1024];
    boost::container::small_vector sm;

    Description of std :: span is available in pdf .

    typename? Forget it in C ++ 20!

    If you were confused when it is necessary to put typename, and when - it is not necessary, then I have good news for you! Starting with C ++ 20 in the vast majority of places it will be possible not to write typename:

    template T::R f();
    template struct S {
        using Ptr = PtrTraits::Ptr;
        T::R f(T::P p) {
            return static_cast(p);
        auto g() -> S::Ptr;

    New Attributes

    • [[no_unique_address]] - if you mark a class variable with this attribute, the compiler will be able to more aggressively optimize its location in memory. For example, it may, in principle, not allocate space for it.
    • [[likely]] - mark them with an expression (for example, `if (flag) {[[likely]] std :: cout <<" OK ";}`) or a case from switch, and the compiler starts optimizing the code, considering that marked the branch will be executed more often than others.
    • [[unlikely]] - tells the compiler that we rarely get to this place on runtime.

    Constexpr metaprogramming

    Sudden breaking news - the committee pre-approved a paper on the use of std :: allocator in constexpr expressions. A huge amount of work remains to be done, but an optimistic forecast is to get std :: vector and std :: string for C ++ 20, which can be used in expressions at the compilation stage. This will allow compilers to optimize better, will allow the use of containers familiar to everyone for reflection, metaprogramming and metaclasses.

    Work in this direction is not progressing as fast as we would like. But, nevertheless, at the meeting they finally approved the paper from RG21 on adding a “constexpr iterator” , which will allow requiring iterators from the container that are applicable at the compilation stage. Our other paper on constexpr themedid not have time to consider.

    If anyone has not seen the story about metaclasses, reflection and people developing these areas, then I recommend watching Herb Sutter “Meta: Thoughts on generative C ++” .

    New primitives for multithreading and vector computing

    Preparing to publish Parallelism 2 TS. The most interesting things, in my opinion, is the data type for SIMD computing, thanks to which you can write optimized cross-platform code. Depending on the platform, a different set of vector instructions will be used under the hood (SSE, AVX, NEON, MDMX, etc.):

    void compute_on_aligned_data(float* data, size_t N) {
        size_t i = 0;
        for (; i + native_simd::size() <= N; i += native_simd::size()) {
            native_simd v(data + i, vector_aligned);
            where(v > 100.f, v) = 100.f + (v - 100.f) * 0.1f;
            v.copy_to(data + i, vector_aligned);
        for (; i < N; ++i) {
            float x = data[i];
            if (x > 100.f) {
                x = 100.f + (x - 100.f) * 0.1f;
            data[i] = x;

    SIMD details are available in the draft proposal .

    Other concurrency innovations (including primitives for fork based concurrency, new multi-threaded algorithms, data type for saving a set of simultaneously occurring exceptions, etc.) are available in the draft .


    A huge amount of time the committee was engaged in the discussion of great new products.


    Added functionality for symmetric coroutines, viewing parameters in promise. For a long time we discussed the problems that users of coroutines encountered. So, for example, the following rather innocent code leads to the crash of the application:

    future​​ ​concat​(const​ std::string​& ​ prefix​, future​​ suffix​) {
        co_return ​ (prefix ​ + ​ co_await suffix​);


    Solved the problems arising from their implementation. Simplified their use. Nothing breakthrough, normal flight.

    Reflection TS

    Began to form a new TS for reflection. So far , this proposal is at the heart of it . Released will not be soon.

    Draper and Oscar Award

    In addition to news directly related to the development of the C ++ language, there is also news on related topics.

    So Björn Straustrup received the prestigious Draper Award for the development of the C ++ language. To which Björn said that this was the merit of the whole WG21, and for all the participants he threw a banquet.

    To other news. Hollywood actors now know about C ++. Upon receiving the Oscars, the creator of Houdini, a popular program for graphic effects, thanked the developers of the C ++ language for C ++ 11 .

    Instead of totals

    The next committee meeting will be in the summer. If you want to change something in C ++ or propose your idea, you can always write on https://stdcpp.ru/ , where people from WP21 will help you convey your desires to the committee.

    Would you like to talk to us live? Look for us at the April C ++ Russia conference in St. Petersburg.

    Want to discuss C ++ with other developers? Telegram chat for beginners and chat for seasoned developers who know the difference between memory_order_relaxed and memory_order_seq_cst are at your service.

    Tell us in the comments what you most expect from C ++ 20 and which of the new products seems most useful to you.

    Also popular now: