C ++ 20およびモジュール、ネットワーク、コルーチン、範囲、グラフィック。 サンディエゴでの会議の結果

C ++ 20までに数年が残っていました。つまり、機能のフリーズはもうすぐです。 すぐに、国際委員会はドラフトC ++ 20のコーミングに焦点を合わせ、C ++ 23で既にイノベーションが追加されます。



サンディエゴでの11月の会議は、機能が凍結される前の最後から2番目の会議です。 C ++ 20に表示される新しいアイテムと、受け入れられた主要なアイテム、および拒否されたアイテム-これらすべてが、あなたを待っています。







char8_t



新しいchar8_tデータ型が追加されました。 これらの文字の配列はUTF-8ストリングです。



std::u8string hello = u8", !";

// TODO:    !
//std::cout << hello; 

      
      





, . .



char8_t — , C++ UTF-8. , C++20 .



char8_t char/unsigned char. , char8_t, , char8_t . , , :



bool do_something(std::u8string_view data, int& result) {
    result += data[0] - u8'0'; //  result 
    return data[0] != u8'0'; //       data[0] 
}

      
      





char (std::string_view), , BYTE PTR [rsi]. char8_t .



, u8«hello» — chat8_t, char. C++11/14/17! char8_t P0482. , C++20 - char8_t.



constexpr



C++20 ( ) , . runtime, , . , , — , , …



- :





, 18–23 2019 , std::string, std::vector ( std::map) .



C++23/26 .





unordered



C++20 unordered :



struct string_hash {
  //       !
  using transparent_key_equal = std::equal_to<>; 

  size_t operator()(std::string_view txt) const { return std::hash<string_view>{}(txt); }
};

using unordered_set_string = std::unordered_set<std::string, string_hash, std::equal_to<> >;

template <class Value>
using unordered_map_string 
    = std::unordered_map<std::string, Value, string_hash, std::equal_to<> >;
// ...
unordered_map_string<int> map = { /* ... */};
assert(map.contains("This does not create a temporary std::string object :-)"));

      
      





, P0919.



std::bind_front



, std::bind — , - . C++20 std::bind_front.



placeholders, ref-qualifiers . :



int foo(int arg1, std::string arg2, std::vector<int>&&, std::string_view);
// ...
auto bound = std::bind_front(foo, 42, "hello");
// ..
int result = bound(std::vector{42, 314, 15}, "word");

      
      





P0356.



std::assume_aligned



, , :



void add(span<float> x, float addition) {
    const auto size = x.size();
    float* ax = std::assume_aligned<64>(x.data());
    for (int i = 0; i < size; ++i)
        ax[i] += factor;
}

      
      





. P1007.



void foo(const Concept auto& value)



P1141 , . , void sort(Sortable auto& c); , sort — , `c` Sortable.



-



std::optional std::variant , copy/move copy/move , . (P0602).



Move- std::function noexcept. std::vector<std::function> std::function noexcept, (P0771).



c make_unique/make_shared, , . new T[x], . , C++20 std::make_unique_default_init std::make_shared_default_init. Boost (P1020).



*_pointer_cast , rvalue. std::shared_ptr (P1224).





P0608 std::variant:



std::variant<std::string, bool> x = "abc";    // !  C++20 `x`  `true`

      
      





P0487 , :



char buffer[64];
std::cin >> buffer;    //    
char* p = get_some_ptr();
std::cin >> p;            //    

      
      





, , (P1289):



struct int_reference {
   // ...
   int get() const [[expects: ptr_ != nullptr ]] { return *ptr_; }
private:
   int* ptr_;
};

      
      





Networking



, . : C++20 . .



Modules



— EWG , C++20. .

, .



C++ .



, , .



Ranges



Ranges C++20 . P0896 . . , — .



, ranges:



#include <algorithm>

std::ranges::sort(some_vector);
std::ranges::find(email.c_str(), std::unreachable_sentinel, '@');
std::ranges::fill(std::counted_iterator(char_ptr, 42), std::default_sentinel, '!');

      
      





Coroutines



, . Coroutines . , , .



Boost.Beast . , , … , resumable .



, — .



2D Graphics



, . (, Boost), , 2D .



21



stacktrace ( . ) C++. . , -, C++20 .



, ( C++ ), , , , - void* , , , , 1, , , .



( , stdcpp.ru). — . .



[[visible]] , P1283. , , .



std::variant, « std::variant », . — std::variant, ( P0608) . .



unordered map (P0652) , : , Concurrent Data Structures TS (, ).



SG6 Numerics , (P0880). , Numbers TS, .



« copy elision», P0889. , , . .



, , Misc constexpr bits P1032, C++20. array, tuple, pair, std::string, back_insert_iterator, front_insert_iterator, insert_iterator.





C++20 : Concepts, Contracts, Ranges, Modules, constexpr .



, 21, C++20. , - , - , , .



C++: 21 - C++ Siberia 2019 .



All Articles