0% found this document useful (0 votes)
17 views

cpp23_refcard_oct_2024.01

Cpp23 ref card

Uploaded by

mohamed.nar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

cpp23_refcard_oct_2024.01

Cpp23 ref card

Uploaded by

mohamed.nar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

C++23 Features Reference Card

Language Features Stacktrace library, P0881 <flat_map> and <flat_set>, P0429 and P1222
New or updated keywords and preprocessor directives: Based on Boost.Stacktrace, allows to get more context when debugging Drop-in replacement for maps and sets with better performance
code. The library defines components to store the stacktrace of the characteristics.
✔ auto - Explicit cast to a prvalue copy
current thread of execution and query information about the stored std::mdspan – multidimensional span, P0009
✔ this – explicit object parameter
✔ if consteval stacktrace at runtime. A generalization over std::span for multiple dimensions. Supports
std::cout << std::stacktrace::current(); dynamic as well as static extents (compile time constants). It also
✔ #elifdef / #elifndef / #warning - for C23 compatibility
Deducing this, P0847, CRTP Example std::is_scoped_enum and std::to_underlying supports various mappings like column-major order, row-major or even
A library support for enums and underlying types. Equivalent to: stride access.
A way to explicitly pass “this” parameter into a member function, gives
static_cast<std::underlying_type_t<Enum>>(e); Formatted output library <print>, P2093
more control and reduce code. Useful for passing this by value,
the trait (underlying_type) has been available since C++11. std::print("{1} {0}!\n", "World”, “Hello”);
recursive lambdas, CRTP and more.
struct Pattern { std::string/std::string_view improvements: New functions in the <print> header: std::print,
template <typename Self> void foo(this Self&& self) ✔ contains(char/string_view/const char*) - member fun std::println (adds a new line) that uses std::format to output
{ self.fooImpl(); } }; ✔ Prohibiting std::basic_string and std::basic_string_view text to stdout. Plus lower-level routines like vprint_unicode with
construction from nullptr more parameters for output.
Extend init-statement to allow alias-declaration, P2360
In C++20 `using` wasn’t allowed in the for loop, now it’s fixed: ✔ Range constructor for std::basic_string_view Standard Library Modules, P2465
for (using T = int; T e : container) { ... } ✔ string::resize_and_overwrite() - Allows us to import std; imports everything in namespace std from C++
initialize/resize strings without clearing the buffer but filling bytes headers and C wrapper headers. It also imports ::operator new etc.
Multidimensional subscript operator, P2128 with some user operation. from <new>.
Change the rules to allow multiple params into the operator[]:
struct Array2D {int operator[](size_t i, size_t j) std::out_ptr(), std::inout_ptr(), P1132 import std.compat; imports all of the above, plus the global
{ return m[i+j*w];} }; Functions that wrap a smart pointer into a special type allowing to pass namespace counterparts for the C wrapper headers.
This is crucial for types like std::mdspan to low level functions that require pointer to pointer parameters. <spanstream>: string-stream with span buffers P0448
Features for Lambdas Ranges and Views additions New classes: basic_spanbuf, basic_ispanstream,
✔ ranges::to<>, P1206 – build a collection from a range basic_ospanstream, basic_spanstream analogous to existing
✔ Attributes on lambdas,
✔ ranges::starts_with() and ranges::ends_with() stream classes but using std::span as the buffer. They allows explicit
✔ () is more optional,
✔ ranges::iota(), ranges::shift_left/right() buffer management and improved performance.
✔ the call operator can be static,
✔ deducing this adds new capabilities like better recursion. ✔ ranges::find_last(_if)(), find_last_if_not() Other (Language & Library)
✔ Change scope of lambda trailing-return-type ✔ ranges::contains() and ranges::contains_subrange() ✔ If consteval { }, P1938
✔ Ranges fold algorithms: ranges::fold_*() ✔ auto(x) and auto{x}, P0849 - eplaces decay_copy
[[assume]] new attribute P1774 ✔ Views: slide, cartesian_product, repeat, enumerate, ✔ static operator() and static operator []
[[assume]] Specifies that an expression will always evaluate to true at adjacent(_transform), as_rvalue, as_const, stride, ✔ CTAD from inherited constructors
a given point. It standardizes the existing vendor specific semantics like chunk(_by), join_with, zip(_transform) ✔ Unicode improvements
__builtin_assume (Clang) and __assume (MSVC, ICC). Offers potential
Heterogeneous erasure for associative containers, P2077 ✔ std::visit() for classes derived from std::variant
optimization opportunities for compilers. ✔ std::unreachable()
Continuation of the work for heterogeneous operations. This time you
constexpr Updates P2448, P2647 and P2242 can use transparent comparators for erase() and extract() ✔ Deprecating std::aligned_storage and aligned_union
✔ Relax rules for constructors and return types for constexpr member functions. To be backward compatible the comparators cannot ✔ Simpler implicit move P2266
functions, making it almost identical to regular functions. be convertible to iterator or const_iterator of a given container. ✔ Pipe support for user-defined range adaptors, P2387
✔ Permitting static constexpr variables in constexpr functions ✔ std::format improvements – formatting ranges, compile time parsing
Monadic operations for std::optional, P0798 and more
Extend Lifetime of Temporaries in range based for, P2718 New member functions for optional: and_then, transform and or_else. ✔ constexpr std::unique_ptr, P2273
The lifetime of temporary objects in the for‐range‐initializer is extended auto ret = userName.transform(toUpper)
✔ constexpr to_chars() and from_chars() for integers, P2291
until the end of the loop. C++20 code below generates UB as the .and_then([](string x) { ... }
✔ Explicit lifetime management, P2590
temporary object is destroyed when the function returns. .or_else...
✔ Literal suffix for (signed) size_t – uz, UZ, P0330
std::vector<std::vector<int>> getVector(); <expected> and monadic operations, P0323
for (auto e : getVector()[0]) References
A vocabulary type that allows storing either of two values: T or isocpp.org,
Library Features unexpected (in a form of some error Type). en.cppreference.com/w/cpp/compiler_support
std::generator coroutine generator, P2502 Enum FuelErr { … } www.cppstories.com
A library support for a synchronous generator. It models view and std::expected<double, FuelErr> calcFuel(int dst);
input_range of the elements yielded by the evaluation of a co-routine. Get Extended Version of this ref card @CppStories Patreon

© 2024 Bartlomiej Filipek, www.cppstories.com, Extended version at: https://www.patreon.com/posts/c-23-referece-ex-114749235 Last update October 2024

You might also like