捆绑了C ++ 20,启动了C ++ 23。 科隆会议的结果

前几天,国际标准化委员会C ++在科隆举行了会议。 上一次,C ++ 20中采用了功能冻结,因此委员会仅应讨论对已被接受的事物的更正,并添加C ++ 23中已存在的新功能...

...但事实并非如此!



他们对std :: flat_map做了什么? 可怕的关键字co_return,co_await和co_yield是否会保留; 您是否完成了std ::格式? C ++ 20中将使用哪种合同? 所有这些都在等待您的削减。

进化工作组


星期一


这一天很忙-我们决定重命名snake_case中的所有概念,而不是CamelCase。 此外,由于投票率很高 ,他们采用了提案P1607 ,该提案将合同的语法和行为更改为更易于理解(但也需要宏)。

周二


讨论Corutins。 拒绝一切,包括我们建议从协程关键字中删除co_的建议。 las

星期三


突然我们意识到,实际上没有人批准星期一批准的提案P1607 ,讨论了大约30分钟,而有关合同的现有决定却经过了多年的磨练。

经过长时间的讨论,他们认为合同原则上尚未为C ++ 20准备好。 并将其从标准中删除。

星期四星期五


讨论C ++ 23。 主要力量集中在错误处理的新机制上。 关于该主题既有一般的思想 ,也有针对新的throws异常说明符的具体建议。

图书馆工作组


该委员会有一个LWG分组。 任何向标准库添加功能的文档都应在此子组中进行审核。

LWG的平均吞吐量为每周〜30个文档。 在科隆,有必要考虑50多个文档,其中大约一半是令人印象深刻的尺寸,例如:
* std :: flat_map
* std :: jthread
* 标准库的运算符<=>
* 新的同步原语
+ Paper来自EWG,用于在snake_case中重命名概念。

哪个先前批准的成功拖动到C ++ 20


  • 在constexpr中,现在不必对每个变量进行零初始化 。 int i {};下的int i;万岁。
  • require现在可以用于构造函数和析构函数。 因此,现在在该类中可以有几个析构函数:

    #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/zh-CN458938/


All Articles