{"id":9830,"date":"2024-08-12T08:16:49","date_gmt":"2024-08-12T08:16:49","guid":{"rendered":"https:\/\/www.modernescpp.com\/?p=9830"},"modified":"2024-08-12T09:28:36","modified_gmt":"2024-08-12T09:28:36","slug":"c23-this-and-that","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/c23-this-and-that\/","title":{"rendered":"C++23: This and That"},"content":{"rendered":"\n<p>I have already written 10 posts about C++23. Today, I want to discuss the features I forgot in the first round.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1030\" height=\"349\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/TimelineCpp-1030x349.png\" alt=\"\" class=\"wp-image-9831\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/TimelineCpp-1030x349.png 1030w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/TimelineCpp-300x102.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/TimelineCpp-768x260.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/TimelineCpp-705x239.png 705w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/TimelineCpp.png 1210w\" sizes=\"auto, (max-width: 1030px) 100vw, 1030px\" \/><\/figure>\n\n\n\n<p> As a short reminder, here are the main C++23 features.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Main C++23 Features<\/h2>\n\n\n\n<p>C++23 offers with deducing this a small but very impactful feature of the core language. Deducing this allows you, similar to Python, to make the implicitly passed this pointer in a member function definition explicit. Thanks to deducing this, a few complex techniques in C++, such as CRTP or the Overload Pattern, will become a piece of cake.<\/p>\n\n\n\n<p>The C++23 library will get many impactful additions. You can directly import the standard library with<code> import std;,<\/code> or apply the C++20 format string in<code> std::print<\/code> and<code> std::println<\/code>. Additionally, we will get flat associative containers such as <code>std::flat_map<\/code> for performance reasons.<code> std::flap_map<\/code> is a drop-in replacement for <code>std::map<\/code>. <code>std::optional<\/code> interface is extended with a monadic interface for composability. The new data type <code>std::expected<\/code> already has a composable interface and can store an expected or an unexpected value for error handling. Thanks to <code>std::mdspan<\/code>, we will get a multidimensional span. Finally,<code> std::generator<\/code> is the first concrete coroutine for creating a stream of numbers. <code>std::generator<\/code> is part of the ranges library, which will also be improved in C++23.<\/p>\n\n\n\n<p> If you need more details, read my previous posts.<\/p>\n\n\n\n<p>Core Language<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/c23-deducing-this\/\">C++23: Deducing This<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/c23-syntactic-sugar-with-deducing-this\/\">C++23: Syntactic Sugar with Deducing This<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/c23-the-small-pearls-in-the-core-language\/\">C++23: The Small Pearls in the Core Language<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/c23-more-small-pearls\/\">C++23: More Small Pearls<\/a><\/li>\n<\/ol>\n\n\n\n<p>Library<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/c23-a-modularized-standard-library-stdprint-and-stdprintln\/\">C++23: A Modularized Standard Library, std::print and std::println<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/ranges-improvements-with-c-23\">Range Improvements with C++23<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/c23-a-new-way-of-error-handling-with-stdexpected\/\">C++23: A New Way of Error Handling with std::expected<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/c23-a-multidimensional-view\/\">C++23: A Multidimensional View<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.modernescpp.com\/index.php\/c23-ranges-improvements-and-stdgenerator\/\">C++23: Range Improvements and std::generator<\/a><\/li>\n<\/ol>\n\n\n\n<p> This is not all.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Fixed Width Floating Point Types<\/h2>\n\n\n\n<p> So far, C++ supports the following floating point types: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>no suffix: double<\/li>\n\n\n\n<li>f or F suffix: float<\/li>\n\n\n\n<li>l or L suffix: long double<\/li>\n<\/ul>\n\n\n\n<p>With C++23, we will get five new literal suffixes.<\/p>\n\n\n\n<p>The table from cppreference shows their types and their properties.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1020\" height=\"276\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/floating.png\" alt=\"\" class=\"wp-image-9834\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/floating.png 1020w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/floating-300x81.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/floating-768x208.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/floating-705x191.png 705w\" sizes=\"auto, (max-width: 1020px) 100vw, 1020px\" \/><\/figure>\n\n\n\n<p>The new data types are defined in the header <code>&lt;stdfloat&gt;<\/code>. You can check with the corresponding predefined macro, if your implementation supports the new data types. Then the macro is 1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Stacktrace<\/h2>\n\n\n\n<p>Analyzing the current call stack is often very useful for debugging. The new stack trace library supports precisely this.<\/p>\n\n\n\n<p>The library consists of two classes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>stacktrace_entry<\/code>: representation of an evaluation in a stack trace<\/li>\n\n\n\n<li><code>basic_stacktrace<\/code>: a snapshot of the whole stack trace or its given part<\/li>\n<\/ul>\n\n\n\n<p>Let me put this in simpler words. The <code>stacktrace_entry<\/code> class lets you get information about an evaluation in a stack trace. Each <code>stacktrace_entry<\/code> object is either empty, or represents an evaluation in a stack trace.<\/p>\n\n\n\n<p>The <code>basic_stacktrace<\/code> class is a snapshot of the whole stack trace or its given part.<\/p>\n\n\n\n<p>Still not clear?<\/p>\n\n\n\n<p>In the following simple example, the <code>main <\/code>function invokes the <code>func1 <\/code>function, <code>func1<\/code> invokes <code>func2<\/code>, and <code><code>func2<\/code><\/code> invokes <code>func3<\/code>.<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #0099FF; font-style: italic\">\/\/ stacktrace1.cpp<\/span>\n\n<span style=\"color: #009999\">#include &lt;iostream&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;stacktrace&gt;<\/span>\n\n \n<span style=\"color: #007788; font-weight: bold\">void<\/span> <span style=\"color: #CC00FF\">func3<\/span>() {\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>stacktrace<span style=\"color: #555555\">::<\/span>current()  <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n}\n \n<span style=\"color: #007788; font-weight: bold\">void<\/span> <span style=\"color: #CC00FF\">func2<\/span>() {\n    func3();\n}\n \n<span style=\"color: #007788; font-weight: bold\">void<\/span> <span style=\"color: #CC00FF\">func1<\/span>() {\n    func2(); \n}\n \n<span style=\"color: #007788; font-weight: bold\">int<\/span> <span style=\"color: #CC00FF\">main<\/span>() {\n    func1();\n}\n<\/pre><\/div>\n\n\n\n<p><code>func3 <\/code>calls the static function <code>current <\/code>on <code>std::stacktrace<\/code>. <code>std::stacktrace<\/code> is an alias for<code> std::basic_stacktrace<\/code> with the default allocator.<\/p>\n\n\n\n<p>Executing the program gives you information about the stack trace.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"452\" height=\"244\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/stacktrace1.png\" alt=\"\" class=\"wp-image-9850\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/stacktrace1.png 452w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/stacktrace1-300x162.png 300w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/figure>\n\n\n\n<p>Compiling the program on the Compiler Explorer was pretty challenging. It took me a while to find the appropriate GCC version and the libraries.  <\/p>\n\n\n\n<p>Here is the command line for g++ 13.1: <code>g++ -std=c++23 -lstdc++_libbacktrace<\/code>.<\/p>\n\n\n\n<p>Thanks to the <code>std::stacktrace_entry<\/code>, you can query the stack trace.<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #0099FF; font-style: italic\">\/\/ stacktrace2.cpp<\/span>\n\n<span style=\"color: #009999\">#include &lt;iostream&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;stacktrace&gt;<\/span>\n\n \n<span style=\"color: #007788; font-weight: bold\">void<\/span> <span style=\"color: #CC00FF\">func3<\/span>() {\n    <span style=\"color: #006699; font-weight: bold\">auto<\/span> stacktrace <span style=\"color: #555555\">=<\/span> std<span style=\"color: #555555\">::<\/span>stacktrace<span style=\"color: #555555\">::<\/span>current();\n    <span style=\"color: #006699; font-weight: bold\">for<\/span> (<span style=\"color: #006699; font-weight: bold\">const<\/span> <span style=\"color: #006699; font-weight: bold\">auto<\/span><span style=\"color: #555555\">&amp;<\/span> entry<span style=\"color: #555555\">:<\/span> stacktrace) {\n        std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&quot;Description: &quot;<\/span> <span style=\"color: #555555\">&lt;&lt;<\/span> entry.description() <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n        std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&quot;file: &quot;<\/span> <span style=\"color: #555555\">&lt;&lt;<\/span> entry.source_file() <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&quot; and line: &quot;<\/span> <span style=\"color: #555555\">&lt;&lt;<\/span> entry.source_line() <span style=\"color: #555555\">&lt;&lt;<\/span><span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n        std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    }\n}\n \n<span style=\"color: #007788; font-weight: bold\">void<\/span> <span style=\"color: #CC00FF\">func2<\/span>() {\n    func3();\n}\n \n<span style=\"color: #007788; font-weight: bold\">void<\/span> <span style=\"color: #CC00FF\">func1<\/span>() {\n    func2(); \n}\n \n<span style=\"color: #007788; font-weight: bold\">int<\/span> <span style=\"color: #CC00FF\">main<\/span>() {\n    func1();\n}\n<\/pre><\/div>\n\n\n\n<p>In the function func3, I iterate through the stack trace entries and expressly display its description, file, and line.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"625\" height=\"705\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/stacktrace2.png\" alt=\"\" class=\"wp-image-9852\" style=\"width:550px\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/stacktrace2.png 625w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/stacktrace2-266x300.png 266w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<p>I will only write a few words about the remaining C++23 features. The examples are from cppreference.com.<\/p>\n\n\n\n<p> Let me start with two features which may affect the performance of your program.<\/p>\n\n\n\n<p> <code>std::unreachable <\/code><\/p>\n\n\n\n<p>You can use <code>std::unreachable <\/code>it to mark code that isn&#8217;t reachable. When you call <code>std::unreachable,<\/code> you&#8217;ll get undefined behavior.<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #0099FF; font-style: italic\">\/\/ from https:\/\/en.cppreference.com\/w\/cpp\/utility\/unreachable<\/span>\n\n<span style=\"color: #006699; font-weight: bold\">switch<\/span> (xy)\n{\n<span style=\"color: #006699; font-weight: bold\">case<\/span> <span style=\"color: #FF6600\">128<\/span>: [[fallthrough]];\n<span style=\"color: #006699; font-weight: bold\">case<\/span> <span style=\"color: #FF6600\">256<\/span>: [[fallthrough]];\n<span style=\"color: #006699; font-weight: bold\">case<\/span> <span style=\"color: #FF6600\">512<\/span>: <span style=\"color: #0099FF; font-style: italic\">\/* ... *\/<\/span>\n    tex.clear();\n    tex.resize(xy <span style=\"color: #555555\">*<\/span> xy, Color{<span style=\"color: #FF6600\">0<\/span>, <span style=\"color: #FF6600\">0<\/span>, <span style=\"color: #FF6600\">0<\/span>, <span style=\"color: #FF6600\">0<\/span>});\n    <span style=\"color: #006699; font-weight: bold\">break<\/span>;\n<span style=\"color: #9999FF\">default:<\/span>\n    std<span style=\"color: #555555\">::<\/span>unreachable();\n}\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><code>std::move_only_function<\/code><\/h2>\n\n\n\n<p> With C++11 we got <code>std::function. std::function <\/code>is a polymorphic function wrapper. Therefore, it can take arbitrary callables and give them a name.&nbsp; Callables are all entities that behave like functions, such as functions, function objects, or lambdas. <\/p>\n\n\n\n<p>Read more about <code>std::function<\/code> here: <a href=\"https:\/\/www.modernescpp.com\/index.php\/functional-in-tr1-and-c-11\/\">Functional in TR1 and C++11<\/a>.<\/p>\n\n\n\n<p>On the contrary to <code>std::function<\/code>, can <code>std::move_only_function<\/code> only get a constructible callable. The callable object may be stored in the <code>std::move_only_function<\/code> to avoid memory allocation.<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #9999FF\">\/\/ from https:<\/span><span style=\"color: #0099FF; font-style: italic\">\/\/en.cppreference.com\/w\/cpp\/utility\/functional\/move_only_function<\/span>\n\n\n<span style=\"color: #006699; font-weight: bold\">auto<\/span> lambda <span style=\"color: #555555\">=<\/span> [task <span style=\"color: #555555\">=<\/span> std<span style=\"color: #555555\">::<\/span>move(packaged_task)]() <span style=\"color: #006699; font-weight: bold\">mutable<\/span> { task(); };\n \n<span style=\"color: #0099FF; font-style: italic\">\/\/  std::function&lt;void()&gt; function = std::move(lambda); \/\/ Error<\/span>\nstd<span style=\"color: #555555\">::<\/span>move_only_function<span style=\"color: #555555\">&lt;<\/span><span style=\"color: #007788; font-weight: bold\">void<\/span>()<span style=\"color: #555555\">&gt;<\/span> function <span style=\"color: #555555\">=<\/span> std<span style=\"color: #555555\">::<\/span>move(lambda); <span style=\"color: #0099FF; font-style: italic\">\/\/ OK<\/span>\n \n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><code>std::byteswap<\/code><\/h2>\n\n\n\n<p><code>std::byteswap<\/code> swaps the bytes in the value <code>n<\/code>.<code> n <\/code>must be <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/concepts\/integral\">integral<\/a>.<\/p>\n\n\n\n<p> The following program applies <code>std::byteswap<\/code>.<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #9999FF\">\/\/ from https:<\/span><span style=\"color: #0099FF; font-style: italic\">\/\/en.cppreference.com\/w\/cpp\/numeric\/byteswap<\/span>\n\n<span style=\"color: #009999\">#include &lt;bit&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;concepts&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;cstdint&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;iomanip&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;iostream&gt;<\/span>\n \n<span style=\"color: #006699; font-weight: bold\">template<\/span><span style=\"color: #555555\">&lt;<\/span>std<span style=\"color: #555555\">::<\/span>integral T<span style=\"color: #555555\">&gt;<\/span>\n<span style=\"color: #007788; font-weight: bold\">void<\/span> dump(T v, <span style=\"color: #007788; font-weight: bold\">char<\/span> term <span style=\"color: #555555\">=<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>)\n{\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>hex <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>uppercase <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>setfill(<span style=\"color: #CC3300\">&#39;0&#39;<\/span>)\n              <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>setw(<span style=\"color: #006699; font-weight: bold\">sizeof<\/span>(T) <span style=\"color: #555555\">*<\/span> <span style=\"color: #FF6600\">2<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> v <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&quot; : &quot;<\/span>;\n    <span style=\"color: #006699; font-weight: bold\">for<\/span> (std<span style=\"color: #555555\">::<\/span><span style=\"color: #007788; font-weight: bold\">size_t<\/span> i{}; i <span style=\"color: #555555\">!=<\/span> <span style=\"color: #006699; font-weight: bold\">sizeof<\/span>(T); <span style=\"color: #555555\">++<\/span>i, v <span style=\"color: #555555\">&gt;&gt;=<\/span> <span style=\"color: #FF6600\">8<\/span>)\n        std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>setw(<span style=\"color: #FF6600\">2<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #006699; font-weight: bold\">static_cast<\/span><span style=\"color: #555555\">&lt;<\/span><span style=\"color: #007788; font-weight: bold\">unsigned<\/span><span style=\"color: #555555\">&gt;<\/span>(T(<span style=\"color: #FF6600\">0xFF<\/span>) <span style=\"color: #555555\">&amp;<\/span> v) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39; &#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>dec <span style=\"color: #555555\">&lt;&lt;<\/span> term;\n}\n \n<span style=\"color: #007788; font-weight: bold\">int<\/span> main()\n{\n    static_assert(std<span style=\"color: #555555\">::<\/span>byteswap(<span style=\"color: #CC3300\">&#39;a&#39;<\/span>) <span style=\"color: #555555\">==<\/span> <span style=\"color: #CC3300\">&#39;a&#39;<\/span>);\n \n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&quot;byteswap for U16:<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">&quot;<\/span>;\n    constexpr <span style=\"color: #006699; font-weight: bold\">auto<\/span> x <span style=\"color: #555555\">=<\/span> std<span style=\"color: #555555\">::<\/span><span style=\"color: #007788; font-weight: bold\">uint16_t<\/span>(<span style=\"color: #FF6600\">0xCAFE<\/span>);\n    dump(x);\n    dump(std<span style=\"color: #555555\">::<\/span>byteswap(x));\n \n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&quot;<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">byteswap for U32:<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">&quot;<\/span>;\n    constexpr <span style=\"color: #006699; font-weight: bold\">auto<\/span> y <span style=\"color: #555555\">=<\/span> std<span style=\"color: #555555\">::<\/span><span style=\"color: #007788; font-weight: bold\">uint32_t<\/span>(<span style=\"color: #FF6600\">0xDEADBEEFu<\/span>);\n    dump(y);\n    dump(std<span style=\"color: #555555\">::<\/span>byteswap(y));\n \n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&quot;<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">byteswap for U64:<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">&quot;<\/span>;\n    constexpr <span style=\"color: #006699; font-weight: bold\">auto<\/span> z <span style=\"color: #555555\">=<\/span> std<span style=\"color: #555555\">::<\/span><span style=\"color: #007788; font-weight: bold\">uint64_t<\/span>{<span style=\"color: #FF6600\">0x0123456789ABCDEFull<\/span>};\n    dump(z);\n    dump(std<span style=\"color: #555555\">::<\/span>byteswap(z));\n}\n<\/pre><\/div>\n\n\n\n<p>Finally, here is the output of the program.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"538\" height=\"351\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/byteswap.png\" alt=\"\" class=\"wp-image-9857\" style=\"width:450px;height:auto\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/byteswap.png 538w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/08\/byteswap-300x196.png 300w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p> With my next post, I jump into C++26<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have already written 10 posts about C++23. Today, I want to discuss the features I forgot in the first round. As a short reminder, here are the main C++23 features. Main C++23 Features C++23 offers with deducing this a small but very impactful feature of the core language. Deducing this allows you, similar to [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":9831,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[378],"tags":[],"class_list":["post-9830","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-23"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/9830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=9830"}],"version-history":[{"count":25,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/9830\/revisions"}],"predecessor-version":[{"id":9863,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/9830\/revisions\/9863"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/9831"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=9830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=9830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=9830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}