{"id":4554,"date":"2022-11-08T11:23:09","date_gmt":"2022-11-08T09:23:09","guid":{"rendered":"https:\/\/mariusbancila.ro\/blog\/?p=4554"},"modified":"2022-11-08T11:23:12","modified_gmt":"2022-11-08T09:23:12","slug":"three-new-utility-functions-in-cpp23","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/","title":{"rendered":"Three new utility functions in C++23"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Some time ago I wrote a blog post called <a href=\"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Three C++23 features for common use<\/a>. In this article, I want to continue on that idea and discuss three new utility functions that were added to C++23.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">std::unreachable<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This new function is available in the <code>&lt;utility><\/code> header. It&#8217;s intended to be used when you know you have an execution path in your code that cannot be reached but the compiler cannot figure that out. Informing the compiler could help to optimize impossible code branches.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A typical use case for this function are switch statements on a variable that can take only a limited set of values from its domain. For instance, an integer that can only be between 0 &#8211; 9. Here is a simple example with a switch that checks a <code>char<\/code> value and executes operations. Only a limited number of commands are supported but the argument is checked before invoking the function so it shouldn&#8217;t be possible to receive other values than already handled in the switch.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void execute_command(char ch)\n{\n   switch (ch)\n   {\n   case 'a':\n      \/* add *\/ break;\n   case 'd':\n      \/* delete *\/ break;\n   default:\n      std::unreachable();\n   }\n}\n\nbool is_valid(char ch)\n{\n   return ch == 'a' || ch == 'd';\n}\n\nint main()\n{\n   char ch = 0;\n   while (!is_valid(ch))\n      std::cin >> ch;\n   execute_command(ch);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It could be argued though that it might be safer to handle the default case in some way to ensure safe failure rather than assume that a variable\/argument would always take a limited number of values. This depends on the particularities of your code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It should be noted that <code>std::unreachable<\/code> invokes undefined behavior. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Learn more<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/utility\/unreachable\" target=\"_blank\" rel=\"noopener\" title=\"\">std::unreachable<\/a><\/li><li><a href=\"https:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2021\/p0627r6.pdf\" target=\"_blank\" rel=\"noopener\" title=\"\">P0627R6: Function to mark unreachable code<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">std::to_underlying<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is yet another utility function from the <code>&lt;utility><\/code> header. It converts an enumeration to its underlying type. It is basically syntactic sugar for the expression <code>static_cast&lt;std::underlying_type_t&lt;Enum>>(e)<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at an example. Consider the following program:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void apply_style(int style)\n{\n   std::cout &lt;&lt; std::format(\"applying style {}\\n\", style);\n}\n\nenum class styles\n{\n   A = 0x1,\n   B = 0x2,\n   C = 0x8000\n};\n\nint main()\n{\n   apply_style(static_cast&lt;int>(styles::C));\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You need a <code>static_cast<\/code> to convert from the scoped enum <code>styles<\/code> to <code>int<\/code>. This can be simplified using <code>std::to_underlying<\/code>, as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">int main()\n{\n   apply_style(std::to_underlying(styles::C));\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>static_cast<\/code> is actually moved to the body of this function, whose implementation can be as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">template &lt;typename Enum>\nconstexpr auto to_underlying(Enum e) noexcept\n{\n    return static_cast&lt;std::underlying_type_t&lt;Enum>>(e);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Learn more<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/utility\/to_underlying\" target=\"_blank\" rel=\"noopener\" title=\"\">std::to_underlying<\/a><\/li><li><a href=\"https:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2021\/p1682r3.html\" target=\"_blank\" rel=\"noopener\" title=\"\">P1682R3 std::to_underlying for enumerations<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">std::byteswap<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This utility function is available in the <code>&lt;bit><\/code> header and reverses the bytes of an integral value. This is an addition to the bit utilities added with this header in C++20. Its purpose is to allow developers perform this byte reversal in a performant way without relying to compiler intrinsics.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is an example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">template &lt;std::integral T>\nvoid print_hex(T v)\n{\n   for (std::size_t i = 0; i &lt; sizeof(T); ++i, v >>= 8)\n   {\n      std::cout &lt;&lt; std::format(\"{:02X} \", static_cast&lt;unsigned>(T(0xFF) &amp; v));\n   }\n   std::cout &lt;&lt; '\\n';\n}\n\nint main()\n{\n   unsigned char a = 0xBA;\n   print_hex(a);                    \/\/ BA\n   print_hex(std::byteswap(a));     \/\/ BA\n\n   unsigned short b = 0xBAAD;\n   print_hex(b);                    \/\/ AD BA\n   print_hex(std::byteswap(b));     \/\/ BA AD\n\n   int c = 0xBAADF00D;\n   print_hex(c);                    \/\/ 0D F0 AD BA\n   print_hex(std::byteswap(c));     \/\/ BA AD F0 0D\n\n   long long d = 0xBAADF00DBAADC0FE;\n   print_hex(d);                    \/\/ FE C0 AD BA 0D F0 AD BA\n   print_hex(std::byteswap(d));     \/\/ BA AD F0 0D BA AD C0 FE\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Byte swapping is important when transferring data between system that use different order for the sequence of bytes stores in memory. This is called endianness. In Big Endian systems, the most significant byte is stored at the smaller address (first). In Little Endian systems, the least significant byte is stored at the smaller address. x86\/x64 architectures use the little endian format. ARM supports both little and big endianness. Network protocols specify big endian for the order of transmission which requires swapping to\/from systems using little endian order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Learn more<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/numeric\/byteswap\" target=\"_blank\" rel=\"noopener\" title=\"\">std::byteswap<\/a><\/li><li><a href=\"https:\/\/isocpp.org\/files\/papers\/P1272R4.html\" target=\"_blank\" rel=\"noopener\" title=\"\">P1272R4 Byteswapping for fun&amp;&amp;nuf<\/a><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">All these utility functions are supported by the major compilers. You can check the compiler support matrix <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/compiler_support\/23\" target=\"_blank\" rel=\"noopener\" title=\"\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some time ago I wrote a blog post called Three C++23 features for common use. In this article, I want to continue on that idea and discuss three new utility functions that were added to C++23.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7],"tags":[451,632],"class_list":["post-4554","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-c23"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,c++23\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Three new utility functions in C++23\" \/>\n\t\t<meta property=\"og:description\" content=\"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-11-08T09:23:09+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-11-08T09:23:12+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Three new utility functions in C++23\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#article\",\"name\":\"Three new utility functions in C++23\",\"headline\":\"Three new utility functions in C++23\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2022-11-08T11:23:09+02:00\",\"dateModified\":\"2022-11-08T11:23:12+02:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#webpage\"},\"articleSection\":\"C++, C++, C++23\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#listItem\",\"name\":\"Three new utility functions in C++23\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#listItem\",\"position\":5,\"name\":\"Three new utility functions in C++23\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/\",\"name\":\"Three new utility functions in C++23\",\"description\":\"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/11\\\/08\\\/three-new-utility-functions-in-cpp23\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2022-11-08T11:23:09+02:00\",\"dateModified\":\"2022-11-08T11:23:12+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Three new utility functions in C++23","description":"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/","robots":"max-image-preview:large","keywords":"c++,c++23","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#article","name":"Three new utility functions in C++23","headline":"Three new utility functions in C++23","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2022-11-08T11:23:09+02:00","dateModified":"2022-11-08T11:23:12+02:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#webpage"},"articleSection":"C++, C++, C++23"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#listItem","name":"Three new utility functions in C++23"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#listItem","position":5,"name":"Three new utility functions in C++23","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/","name":"Three new utility functions in C++23","description":"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2022-11-08T11:23:09+02:00","dateModified":"2022-11-08T11:23:12+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Three new utility functions in C++23","og:description":"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap.","og:url":"https:\/\/mariusbancila.ro\/blog\/2022\/11\/08\/three-new-utility-functions-in-cpp23\/","article:published_time":"2022-11-08T09:23:09+00:00","article:modified_time":"2022-11-08T09:23:12+00:00","twitter:card":"summary","twitter:title":"Three new utility functions in C++23","twitter:description":"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap."},"aioseo_meta_data":{"post_id":"4554","title":null,"description":"Explore three new utility functions available in the C++23 standard: unreachable, to_underlying, and byteswap.","keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-11-08 06:43:22","updated":"2025-12-12 07:57:11","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Some time ago I wrote a blog post called Three C++23 features for common use. In this article, I want to continue on that idea and discuss three new utility functions that were added to C++23.","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++23<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">C++23<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 4 years ago","modified":"Updated 4 years ago"},"absolute_dates":{"created":"Posted on November 8, 2022","modified":"Updated on November 8, 2022"},"absolute_dates_time":{"created":"Posted on November 8, 2022 11:23 am","modified":"Updated on November 8, 2022 11:23 am"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-1bs","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=4554"}],"version-history":[{"count":5,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4554\/revisions"}],"predecessor-version":[{"id":4559,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4554\/revisions\/4559"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=4554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=4554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=4554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}