{"id":4426,"date":"2022-01-17T08:09:45","date_gmt":"2022-01-17T06:09:45","guid":{"rendered":"https:\/\/mariusbancila.ro\/blog\/?p=4426"},"modified":"2022-01-17T08:09:47","modified_gmt":"2022-01-17T06:09:47","slug":"three-cpp23-features-for-common-use","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/","title":{"rendered":"Three C++23 features for common use"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">C++23 is the current working version of the C++ standard. No major feature has been included so far, but a series of smaller ones as well as many defect reports have made it already to the standard. You can check the current status as well as the compiler support for the new features <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/23\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>. Many of these new features are small improvements or things you probably wouldn&#8217;t use on a regular basis. However, I want to point here to three C++23 features that, in my opinion, stand out among the others as more likely to be used more often.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Literal suffixes for size_t and ptrdiff_t<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/types\/size_t\" target=\"_blank\" rel=\"noreferrer noopener\">std::size_t<\/a> is an unsigned data type (of at least 16 bits) that can hold the maximum size of an object of any type. It can safely store the index of an array on any platform. It is the type returned by the <code>sizeof<\/code>, <code>sizeof...<\/code>, and <code>alignof<\/code> operators.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/types\/ptrdiff_t\" target=\"_blank\" rel=\"noreferrer noopener\">std::ptrdiff_t<\/a> is a signed data type (of at least 17 bits) that represents the type of the result of subtracting two pointers. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In C++23, these have their own string literal suffixes.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-subtle-light-gray-background-color has-background\"><thead><tr><th>Literal suffix<\/th><th>Deduced type<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td><code>uz<\/code> or <code>uZ<\/code> or <code>Uz<\/code> or <code>UZ<\/code><\/td><td><code>std::size_t<\/code><\/td><td><code>auto a = 42uz;<\/code><\/td><\/tr><tr><td><code>z<\/code> or <code>Z<\/code><\/td><td>signed <code>std::size_t<\/code> (<code>std::ptrdiff_t<\/code>)<\/td><td><code>auto b = -42z;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s see how this is useful. In C++20, we could write the following:<\/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=\"\">std::vector&lt;int> v {1, 1, 2, 3, 5, 8};\nfor(auto i = 0u; i &lt; v.size(); ++i)\n{\n   std::cout &lt;&lt; v[i] &lt;&lt; '\\n';\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The deduced type of the variable <code>i<\/code> is <code>unsigned int<\/code>. This works fine on 32-bit, where both <code>unsigned int<\/code> and <code>size_t<\/code>, which is the return type of the <code>size()<\/code> member function, are 32-bit. But on 64-bit you may get a warning and the value is truncated, because <code>unsigned int<\/code> is still 32-bit but <code>size_t<\/code> is 64-bit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the other hand, we can have the following:<\/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=\"\">std::vector&lt;int> v {1, 1, 2, 3, 5, 8};\nauto m = std::max(42, std::ssize(v)); \/\/ compiles on 32-bit but fails on 64-bit<\/pre>\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=\"\">std::vector&lt;int> v {1, 1, 2, 3, 5, 8};\nauto m = std::max(42ll, std::ssize(v)); \/\/ compiles on 64-bit but fails on 32-bit<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Neither of these two versions work on both 32-bit and 64-bit platforms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is where the new literal suffixes help:<\/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=\"\">std::vector&lt;int> v {1, 1, 2, 3, 5, 8};\nfor(auto i = 0uz; i &lt; v.size(); ++i)\n{\n   std::cout &lt;&lt; v[i] &lt;&lt; '\\n';\n}\n\nauto m = std::max(42z, std::ssize(v));<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This code works the same on all platforms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>See more<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2020\/p0330r8.html\" target=\"_blank\" rel=\"noreferrer noopener\">Literal Suffix for (signed) size_t<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/integer_literal\" target=\"_blank\" rel=\"noreferrer noopener\">Integer literal<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Multidimensional subscript operator<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes we need to work with multidimensional containers (or views). Accessing elements in an unidimensional container can be done with the subscript operator (such as <code>arr[0]<\/code> or <code>v[i]<\/code>). But for a multidimensional type, the subscript operator does not work nice. You cannot say <code>arr[0, 1, 2]<\/code>. The alternatives are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Define an access function, such as <code>at()<\/code> with any number of parameters (so you could say <code>c.at(0, 1, 2)<\/code>)<\/li><li>overload the call operator (so you could say <code>c(0, 1, 2)<\/code>)<\/li><li>overload the subscript operator with a brace-enclosed list (so you could say <code>c[{1,2,3}]<\/code>)<\/li><li>chain single-argument array access operators (so you could say <code>c[0][1][2]<\/code>) which is probably leading to the least desirable APIs and usage<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To demonstrate the point, let&#8217;s consider a matrix class (that represents a two dimensional array). A simplistic implementation and usage is 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 T, size_t R, size_t C>\nstruct matrix\n{\n   T&amp; operator()(size_t const r, size_t const c) noexcept\n   {\n      return data_[r * C + c];\n   }\n\n   T const &amp; operator()(size_t const r, size_t const c) const noexcept\n   {\n      return data_[r * C + c];\n   }\n\n   static constexpr size_t Rows = R;\n   static constexpr size_t Columns = C;\nprivate:\n   std::array&lt;T, R* C> data_;\n};\n\nint main()\n{\n   matrix&lt;int, 2, 3> m;\n   for (size_t i = 0; i &lt; m.Rows; ++i)\n   {\n      for (size_t j = 0; j &lt; m.Columns; ++j)\n      {\n         m(i, j) = i * m.Columns + (j + 1);\n      }\n   }\n\n   for (size_t i = 0; i &lt; m.Rows; ++i)\n   {\n      for (size_t j = 0; j &lt; m.Columns; ++j)\n      {\n         std::cout &lt;&lt; m(i, j) &lt;&lt; ' ';\n      }\n\n      std::cout &lt;&lt; '\\n';\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I never liked the <code>m(i, j)<\/code> syntax, but this was the best we could do until C++23, IMO. Now, we can overload the subscript operator with multiple parameters:<\/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=\"\">T&amp; operator[](size_t const r, size_t const c) noexcept\n{\n   return data_[r * C + c];\n}\n\nT const &amp; operator[](size_t const r, size_t const c) const noexcept\n{\n   return data_[r * C + c];\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We can now use the new <code>matrix<\/code> implementation 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   matrix&lt;int, 3, 2> m;\n   for (size_t i = 0; i &lt; m.Rows; ++i)\n   {\n      for (size_t j = 0; j &lt; m.Columns; ++j)\n      {\n         m[i, j] = i * m.Columns + (j + 1);\n      }\n   }\n    \n   for (size_t i = 0; i &lt; m.Rows; ++i)\n   {\n      for (size_t j = 0; j &lt; m.Columns; ++j)\n      {\n         std::cout &lt;&lt; m[i, j] &lt;&lt; ' ';\n      }\n       \n      std::cout &lt;&lt; '\\n';\n   }    \n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I just wished we had this twenty years ago!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>See also<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/operator_member_access\" target=\"_blank\" rel=\"noreferrer noopener\">Member access operators<\/a><\/li><li><a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2021\/p2128r6.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">Multidimensional subscript operator<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">contains() member function for string\/string_view<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">C++20 added the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string\/starts_with\" target=\"_blank\" rel=\"noreferrer noopener\">starts_with()<\/a> and <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string\/ends_with\" target=\"_blank\" rel=\"noreferrer noopener\">ends_with()<\/a> member functions to <code>std::basic_string<\/code> and <code>std::basic_string_view<\/code>. These enable us to check whether a string starts with a given prefix or ends with a given suffix.<\/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   std::string text = \"lorem ipsum dolor sit amet\";\n\n   std::cout &lt;&lt; std::boolalpha;\n\n   std::cout &lt;&lt; text.starts_with(\"lorem\") &lt;&lt; '\\n'; \/\/ true\n   std::cout &lt;&lt; text.starts_with(\"ipsum\") &lt;&lt; '\\n'; \/\/ false\n\n   std::cout &lt;&lt; text.ends_with(\"dolor\") &lt;&lt; '\\n';   \/\/ false\n   std::cout &lt;&lt; text.ends_with(\"amet\") &lt;&lt; '\\n';    \/\/ true\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Unfortunately, these don&#8217;t help us checking whether a string contains a given substring. Of course, this is possible with the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string\/find\" target=\"_blank\" rel=\"noreferrer noopener\">find()<\/a> function. But this returns the position of the first character of the found substring or <code>npos<\/code> otherwise, so we need to do a check 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=\"\">std::cout &lt;&lt; (text.find(\"dolor\") != std::string::npos) &lt;&lt; '\\n';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"> I find this cumbersome and ugly when you just want to know if a string contains a particular substring or character.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In C++23, the circle is complete, as the same feature is available with the new <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string\/contains\" target=\"_blank\" rel=\"noreferrer noopener\">contains()<\/a> member function. This function enables us to check whether a substring or a single character is present anywhere the string. This is basically the same as <code>find(x) != npos<\/code>. But the syntax is nicer and in line with <code>starts_with()<\/code> and <code>ends_with()<\/code>.<\/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=\"\">std::cout &lt;&lt; text.contains(\"dolor\") &lt;&lt; '\\n';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>See also<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2020\/p1679r3.html\" target=\"_blank\" rel=\"noreferrer noopener\">string contains function<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string\/contains\" target=\"_blank\" rel=\"noreferrer noopener\">basic_string::contains<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string_view\/contains\" target=\"_blank\" rel=\"noreferrer noopener\">basic_string_view::contains<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>C++23 is the current working version of the C++ standard. No major feature has been included so far, but a series of smaller ones as well as many defect reports have made it already to the standard. Many of these new features are small improvements or things you probably wouldn&#8217;t use on a regular basis. However, I want to point here to three C++23 features that, in my opinion, stand out among the others as more likely to be used more often.<\/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-4426","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=\"A look at three new C++23 features that you could potentially use on a regular basis\" \/>\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\/01\/17\/three-cpp23-features-for-common-use\/\" \/>\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 C++23 features for common use\" \/>\n\t\t<meta property=\"og:description\" content=\"A look at three new C++23 features that you could potentially use on a regular basis\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-01-17T06:09:45+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-01-17T06:09:47+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Three C++23 features for common use\" \/>\n\t\t<meta name=\"twitter:description\" content=\"A look at three new C++23 features that you could potentially use on a regular basis\" \/>\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\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#article\",\"name\":\"Three C++23 features for common use\",\"headline\":\"Three C++23 features for common use\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2022-01-17T08:09:45+02:00\",\"dateModified\":\"2022-01-17T08:09:47+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#webpage\"},\"articleSection\":\"C++, C++, C++23\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#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\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#listItem\",\"name\":\"Three C++23 features for common use\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#listItem\",\"position\":5,\"name\":\"Three C++23 features for common use\",\"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\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#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\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/\",\"name\":\"Three C++23 features for common use\",\"description\":\"A look at three new C++23 features that you could potentially use on a regular basis\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/01\\\/17\\\/three-cpp23-features-for-common-use\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2022-01-17T08:09:45+02:00\",\"dateModified\":\"2022-01-17T08:09:47+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 C++23 features for common use","description":"A look at three new C++23 features that you could potentially use on a regular basis","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/","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\/01\/17\/three-cpp23-features-for-common-use\/#article","name":"Three C++23 features for common use","headline":"Three C++23 features for common use","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2022-01-17T08:09:45+02:00","dateModified":"2022-01-17T08:09:47+02:00","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/#webpage"},"articleSection":"C++, C++, C++23"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/#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\/01\/17\/three-cpp23-features-for-common-use\/#listItem","name":"Three C++23 features for common use"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/#listItem","position":5,"name":"Three C++23 features for common use","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\/01\/17\/three-cpp23-features-for-common-use\/#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\/01\/17\/three-cpp23-features-for-common-use\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/","name":"Three C++23 features for common use","description":"A look at three new C++23 features that you could potentially use on a regular basis","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2022-01-17T08:09:45+02:00","dateModified":"2022-01-17T08:09:47+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 C++23 features for common use","og:description":"A look at three new C++23 features that you could potentially use on a regular basis","og:url":"https:\/\/mariusbancila.ro\/blog\/2022\/01\/17\/three-cpp23-features-for-common-use\/","article:published_time":"2022-01-17T06:09:45+00:00","article:modified_time":"2022-01-17T06:09:47+00:00","twitter:card":"summary","twitter:title":"Three C++23 features for common use","twitter:description":"A look at three new C++23 features that you could potentially use on a regular basis"},"aioseo_meta_data":{"post_id":"4426","title":null,"description":"A look at three new C++23 features that you could potentially use on a regular basis","keywords":[],"keyphrases":{"focus":[],"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":{"id":"aioseo-article-6369651303a63","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","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-01-14 20:43:57","updated":"2025-12-12 07:56:25","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":2,"uagb_excerpt":"C++23 is the current working version of the C++ standard. No major feature has been included so far, but a series of smaller ones as well as many defect reports have made it already to the standard. Many of these new features are small improvements or things you probably wouldn't use on a regular basis.&hellip;","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":"2","relative_dates":{"created":"Posted 5 years ago","modified":"Updated 5 years ago"},"absolute_dates":{"created":"Posted on January 17, 2022","modified":"Updated on January 17, 2022"},"absolute_dates_time":{"created":"Posted on January 17, 2022 8:09 am","modified":"Updated on January 17, 2022 8:09 am"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-19o","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4426","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=4426"}],"version-history":[{"count":6,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4426\/revisions"}],"predecessor-version":[{"id":4432,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4426\/revisions\/4432"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=4426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=4426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=4426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}