تم تجميع C ++ 20 ، وتم بدء تشغيل C ++ 23. نتائج الاجتماع في كولونيا

في اليوم الآخر ، كان هناك اجتماع للجنة التقييس الدولية C ++ في كولونيا. آخر مرة ، تم اعتماد تجميد الميزات في C ++ 20 ، لذلك يجب على اللجنة فقط مناقشة تصويبات الأشياء المقبولة بالفعل ، وإضافة عناصر جديدة بالفعل في C ++ 23 ...

... لكنها لم تكن كذلك!



ماذا فعلوا مع الأمراض المنقولة جنسيا :: flat_map ؛ هل ستبقى الكلمات الرئيسية المخيفة ، و co_await ، و co_yield ؛ هل تمكنت من إنهاء std :: format؛ أي نوع من العقود سيكون في C ++ 20؟ كل هذا ينتظرك تحت الخفض.

مجموعة العمل التطورية


الإثنين


كان اليوم مشغولًا - قررنا إعادة تسمية جميع المفاهيم في snake_case بدلاً من CamelCase. بالإضافة إلى ذلك ، تم التعبير على نطاق واسع عن الاقتراح P1607 ، والذي يغير بناء جملة وسلوك العقود إلى اقتراح أكثر قابلية للفهم (ولكن يتطلب أيضًا وحدات ماكرو).

الثلاثاء


ناقش Corutins. تم رفض كل شيء ، بما في ذلك اقتراحنا لإسقاط co_ من الكلمات الرئيسية ل coroutine . للأسف.

الأربعاء


فجأة أدركنا أن لا أحد وافق على اقتراح P1607 الذي تمت الموافقة عليه يوم الاثنين من الناحية العملية ، تمت مناقشته لمدة 30 دقيقة تقريبًا ، في حين أن القرار الحالي بشأن العقود قد تم شحذه لسنوات عديدة.

بعد نقاش طويل ، قرروا أن العقود من حيث المبدأ ليست جاهزة لـ C ++ 20. وإزالتها من المعيار.

الخميس الجمعة


أشياء تمت مناقشتها لـ C ++ 23. تركزت القوى الرئيسية على آليات جديدة في التعامل مع الأخطاء. كانت هناك أفكار عامة حول الموضوع ومقترحات محددة لمحدّد استثناء الرميات الجديد .

مجموعة عمل المكتبة


اللجنة لديها مجموعة فرعية LWG. يجب أن يخضع أي مستند يضيف وظيفة إلى المكتبة القياسية لمراجعة في هذه المجموعة الفرعية.

يبلغ متوسط ​​إنتاجية LWG حوالي 30 مستندًا في الأسبوع. في كولونيا ، كان من الضروري النظر في أكثر من 50 وثيقة ، من بينها حوالي نصف كانت أحجام مثيرة للإعجاب للغاية ، على سبيل المثال:
* الأمراض المنقولة جنسيا :: flat_map
* الأمراض المنقولة جنسيا :: jthread
* المشغل <=> للمكتبة القياسية
* بدايات التزامن الجديد
+ جاء الورق من EWG لإعادة تسمية المفاهيم في snake_case.

أي من تمت الموافقة عليه سابقًا تمكن من السحب إلى C ++ 20


  • في constexpr ، ليس من الضروري الآن تهيئة الصفر لكل متغير . يسقط مع int {} ؛ يعيش int ؛
  • يتطلب يمكن الآن استخدامها للمنشآت والمدمرات. تبعا لذلك ، الآن في الفصل يمكن أن يكون هناك العديد من المدمرات:

    #include <type_traits>
    
    template<typename T>
    struct Optional {
        // ...
        ~Optional() requires(std::is_trivially_destructible_v<T>) = default;
        ~Optional() requires(!std::is_trivially_destructible_v<T>) {
            if (inited_) reinterpret_cast<T&>(data_).~T();
        }
    private:
        bool inited_{false};
        std::aligned_storage_t<sizeof(T), alignof(T)> data_;
    };
    
  • [[nodiscard]] . , :

    template <class F>
    [[nodiscard("Without storing the result the code executes synchronously")]] future async(F&& );
    
    auto test() {
        // ...
    
        // warning: Without storing the result the code executes synchronously
        async([huge_data](){
            std::cerr << huge_data;
        });
    }
    
  • using enum:

    enum class rgba_channel { kRed, kGreen, kBlue, kAlpha};
    
    std::string_view to_string(rgba_channel channel) {
      using enum rgba_channel;
      switch (channel) {
        case kRed:   return "red";
        case kGreen: return "green";
        case kBlue:  return "blue";
        case kAlpha: return "alpha";
      }
    }
    
  • Deduction guides :

    template <typename T>
    struct S {
        T x;
        T y;
    };
    
    S t{'4', '2'}; // Deduces `S<char>`
    
  • __asm constexpr ( !)
  • . :

    void f(int(&)[]); // p.s.:        
    int arr[1];
    
    f(arr);          // OK
    
  • C++20
  • constinit :

    int count_invocations() {
        //   ,   
        //   `counter`  .
        //
        //   -  ,  
        //         
        // `counter`   .
        static constinit std::atomic<int> counter{0};
    
        return ++counter;
    }
    
  • .
  • volatile deprecated. .
  • [[nodiscard]] , :

    struct [[nodiscard]] my_scopeguard { /* ... */ };
    struct my_unique {
        [[nodiscard]] my_unique(int fd) { /* ... */ } //    
        /* ... */
    };
    
    void sample() {
        my_scopeguard(); // warning
        void(my_scopeguard()); // cast  void, warning  
        my_unique(42); // warning
    }
    
  • Class Template Argument Deduction
  • std::vector placement new constexpr
  • <bit> . , / /, — .
  • <format> , chrono locale float:

    constexpr auto birthday = 28d/April/1989;
    string s = format("At {0:%d} of {0:%B}, {0:%Y} someone was born", birthday);
    assert(s == "At 28 of April, 1989 someone was born");
    
  • constexpr bind, invoke, reference_wrapper
  • <numbers>
  • wait notify. conditional_variable:

    #include <atomic>
    
    enum class States {
        kInitial, kProcessing, kPosting,
    };
    
    // !  !
    std::atomic<States> state{States::kInitial};
    
    void state_machine_do_posting() {
        for (;;) {
            States expected_state = States::kProcessing;
    
            //        kProcessing
            state.wait(expected_state);
    
            if (!state.compare_exchange_strong(expected_state, States::kPosting)) {
                continue;
            }
    
            // do something
        }
    }
    
  • snake_case
  • operator != operator ==. , operator <=>
  • std::*stringstream std::basic_stringbuf :

    std::string to_string(const MyType& v) {
        std::string buf;
        constexpr std::size_t kMaxSize = 32;
        buf.reserve(kMaxSize);
    
        //  C++20  ,  C++20 —   
        std::ostringstream oss{std::move(buf)};
        oss << "MyType{" << v << '}';
    
        //  C++20  ,  C++20 — 
        return std::move(oss).str();
    }
    
  • std::jthread:

    #include <thread>
    
    void sample() {
        bool ready = false;
        std::mutex ready_mutex;
        std::condition_variable_any ready_cv; //   `_any`!
    
        std::jthread t([&ready, &ready_mutex, &ready_cv] (std::stop_token st) {
            while (!st.stop_requested()) {
              /* ... */
              {
                std::unique_lock lock{ready_mutex};
    
                //    ready == true,  stop_token.request_stop(),
                //  jthread.request_stop().
                ready_cv.wait_until(lock, [&ready] { return ready; }, st);
              }
              /* ... */
            }
        });
    
        /* ... */
    
        //  `t`  request_stop()       .
    }
    
  • type_traits , .

    antoshkka C++14 CppCon. , . … , .

    , . , type_traits :

    Over dinner at CppCon, Marshall Clow and I discussed a bit of code that relied on two types being layout-compatible. As it happened, the types weren’t layout-compatible after all. I opined that there should be a way to statically assert layout-compatibility, so that the error would be caught at compile time, rather than dinner time. Marshall replied, “Write a proposal.” This is that proposal.
  • std::source_location, , .
  • unordered . .

, std::stacktrace, std::flat_map, std::flat_set C++20 :(

++23


, Boost.Process , /, , , 2d , , JIT C++ .

. std::filesystem::path_view. path_view , .

21


, , , , , , . , , std::format Inf/NaN; jthread; pair, tuple, string, array.

SG1 Concurrency concurrent_unordered_map. visit value , :

concurrent_unordered_map<int, std::string> conc_map;
conc_map.visit(42, [](std::string& value) { // ,  ....
    //    OK.  OK        value.
    std::cerr << value; 

    //    OK.  OK        value.
    value += "Hello"; 
});
.
, :

concurrent_unordered_map<int, std::atomic<int>> conc_map;
conc_map.visit(42, [](std::atomic<int>& value) { // ,  ....
    //  OK
    ++ value; 
});

SG6 Numerics — Numerics TS , wide_integer .


C++ Piter, .

21 ISO 9 ( , ). C++20 C++23.

Source: https://habr.com/ru/post/ar458938/


All Articles