C ++ 20和模块,网络,协程,范围,图形。 圣地亚哥会议的结果

在C ++ 20之前,还剩下几年的时间,这意味着功能冻结即将到来。 不久,国际委员会将集中精力梳理C ++ 20草案,并且C ++ 23中将已经添加了一些创新。

功能冻结之前,11月在圣地亚哥举行的会议是倒数第二次会议。 在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, , . , , — , , …

- :

  • try catch constexpr (P1002).
  • dynamic_cast typeid constexpr (P1327).
  • consteval- ( constexpr!) — , constexpr (P1073).
  • std::is_constant_evaluated(), true, P0595. std::is_constant_evaluated(): .
  • union - constexpr (P1330).
  • constexpr. (P1032, P1006).

, 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 .

Source: https://habr.com/ru/post/zh-CN430406/


All Articles