рд╕реА ++ 20 рд╕реЗ рдкрд╣рд▓реЗ, рдХреБрдЫ рд╕рд╛рд▓ рдмрдиреЗ рд░рд╣реЗ, рдЬрд┐рд╕рдХрд╛ рдорддрд▓рдм рд╣реИ рдХрд┐ рд╕реБрд╡рд┐рдзрд╛ рдлреНрд░реАрдЬ рдХреЛрдиреЗ рдХреЗ рдЪрд╛рд░реЛрдВ рдУрд░ рд╣реИред рдЬрд▓реНрдж рд╣реА, рдЕрдВрддрд░реНрд░рд╛рд╖реНрдЯреНрд░реАрдп рд╕рдорд┐рддрд┐ C ++ 20 рдХреЗ рдорд╕реМрджреЗ рдХрд╛ рдореБрдХрд╛рдмрд▓рд╛ рдХрд░рдиреЗ рдкрд░ рдзреНрдпрд╛рди рдХреЗрдВрджреНрд░рд┐рдд рдХрд░реЗрдЧреА, рдФрд░ рдирд╡рд╛рдЪрд╛рд░реЛрдВ рдХреЛ C ++ 23 рдореЗрдВ рдкрд╣рд▓реЗ рд╣реА рдЬреЛрдбрд╝ рджрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛ред
рдлрд╝реАрдЪрд░ рдлрд╝реНрд░реАрдЬрд╝ рд╕реЗ рдкрд╣рд▓реЗ рд╕реИрди рдбрд┐рдПрдЧреЛ рдореЗрдВ рдирд╡рдВрдмрд░ рдХреА рдмреИрдардХ рддрдкрд╕реНрдпрд╛ рд╣реИред 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. .
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 .