{"id":1809,"date":"2024-06-03T17:23:00","date_gmt":"2024-06-03T17:23:00","guid":{"rendered":"https:\/\/cppdepend.com\/blog\/?p=1809"},"modified":"2024-06-12T10:18:04","modified_gmt":"2024-06-12T10:18:04","slug":"c26-is-coming-but-what-are-the-major-features-that-have-been-added-to-c-since-c11","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/c26-is-coming-but-what-are-the-major-features-that-have-been-added-to-c-since-c11\/","title":{"rendered":"C++26 is coming, but what are the major features that have been added to C++ since C++11?"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<p>Modern C++ has seen a series of significant updates starting from C++11, each bringing new features and enhancements that aim to make the language more efficient, readable, and maintainable. Here&#8217;s a brief overview of the major features introduced in each version since C++11, along with a comment on their usage:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++11<\/h2>\n\n\n\n<p>C++11 marked a significant evolution in the C++ language, introducing several powerful features that modernized and simplified C++ programming. Here are some of the most impactful features, along with examples to illustrate their usage:<\/p>\n\n\n\n<!--more-->\n\n\n\n<h4 class=\"wp-block-heading\">1. Auto type Deduction<\/h4>\n\n\n\n<p>The <code>auto<\/code> keyword allows the compiler to automatically deduce the type of a variable from its initializer.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">auto x = 42;       \/\/ int\nauto y = 3.14;     \/\/ double\nauto s = &quot;hello&quot;;  \/\/ const char*<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>Lambda Expressions<\/strong><\/h4>\n\n\n\n<p>Lambdas provide a concise way to define anonymous functions directly in your code.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">auto add = [](int a, int b) { return a + b; };\nint result = add(3, 4);  \/\/ result is 7<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. <strong>Range-based for Loops<\/strong><\/h4>\n\n\n\n<p>Simplifies iteration over collections like arrays, vectors, and other containers.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">std::vector&lt;int&gt; numbers = {1, 2, 3, 4, 5};\nfor (int n : numbers) {\n    std::cout &lt;&lt; n &lt;&lt; &quot; &quot;;\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4. <strong>Smart Pointers<\/strong><\/h4>\n\n\n\n<p>Introduces <code>std::unique_ptr<\/code> and <code>std::shared_ptr<\/code> to manage dynamic memory automatically, preventing memory leaks.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">std::unique_ptr&lt;int&gt; ptr(new int(10));\n\/\/ No need to delete ptr manually; it will be deleted when it goes out of scope<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">5. <strong>Move Semantics<\/strong><\/h4>\n\n\n\n<p>Move semantics optimize performance by allowing resources to be transferred rather than copied.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">std::vector&lt;int&gt; makeVector() {\n    std::vector&lt;int&gt; v = {1, 2, 3};\n    return v;  \/\/ Moves v rather than copying\n}\n\nstd::vector&lt;int&gt; v = makeVector();  \/\/ Efficient move<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">6. <strong>nullptr<\/strong><\/h4>\n\n\n\n<p>Replaces <code>NULL<\/code> with <code>nullptr<\/code> to represent null pointers more safely.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">int* p = nullptr;  \/\/ p is a null pointer<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">7. <strong>constexpr<\/strong><\/h4>\n\n\n\n<p>Allows for compile-time constant expressions, improving performance by performing computations at compile time.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">constexpr int square(int x) {\n    return x * x;\n}\n\nint arr[square(5)];  \/\/ Creates an array of size 25<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">8. <strong>std::thread<\/strong><\/h4>\n\n\n\n<p>Provides a standard way to create and manage threads, enabling concurrent programming.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;thread&gt;\n#include &lt;iostream&gt;\n\nvoid hello() {\n    std::cout &lt;&lt; &quot;Hello from thread!&quot; &lt;&lt; std::endl;\n}\n\nint main() {\n    std::thread t(hello);\n    t.join();  \/\/ Wait for thread to finish\n    return 0;\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">9. <strong>Variadic Templates<\/strong><\/h4>\n\n\n\n<p>Supports templates with a variable number of arguments, making template programming more flexible.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">template&lt;typename... Args&gt;\nvoid print(Args... args) {\n    (std::cout &lt;&lt; ... &lt;&lt; args) &lt;&lt; std::endl;  \/\/ Fold expression (C++17)\n}\n\nprint(1, 2, &quot;three&quot;, 4.0);<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">10. <strong>Uniform Initialization<\/strong><\/h4>\n\n\n\n<p>Enables a consistent syntax for initializing variables and containers.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">int arr[] = {1, 2, 3};\nstd::vector&lt;int&gt; v = {1, 2, 3, 4, 5};\nstruct Point { int x, y; };\nPoint p = {1, 2};<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">C++14<\/h3>\n\n\n\n<p>C++14 built upon the foundation of C++11, introducing several important enhancements to improve code readability, flexibility, and performance. Here are the major features with examples:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Generic Lambdas<\/h4>\n\n\n\n<p>C++14 allows the use of <code>auto<\/code> in lambda parameter lists, making lambdas more flexible and easier to use with generic code.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">auto add = [](auto a, auto b) { return a + b; };\nstd::cout &lt;&lt; add(1, 2) &lt;&lt; std::endl; \/\/ Output: 3\nstd::cout &lt;&lt; add(1.5, 2.3) &lt;&lt; std::endl; \/\/ Output: 3.8<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. Variable Templates<\/h4>\n\n\n\n<p>Variable templates enable the definition of templates for variables, not just functions or classes.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">template&lt;typename T&gt;\nconstexpr T pi = T(3.1415926535897932385L);\n\nstd::cout &lt;&lt; pi&lt;double&gt; &lt;&lt; std::endl; \/\/ Output: 3.14159\nstd::cout &lt;&lt; pi&lt;float&gt; &lt;&lt; std::endl; \/\/ Output: 3.14159f<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. Return Type Deduction<\/h4>\n\n\n\n<p>C++14 allows functions to deduce their return type automatically using <code>auto<\/code>.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">auto add(int a, int b) {\n    return a + b;\n}\n\nstd::cout &lt;&lt; add(1, 2) &lt;&lt; std::endl; \/\/ Output: 3<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4. std::make_unique<\/h4>\n\n\n\n<p>This utility function simplifies the creation of <code>std::unique_ptr<\/code> instances, making the code more readable and less error-prone.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;memory&gt;\n\nauto ptr = std::make_unique&lt;int&gt;(42);\nstd::cout &lt;&lt; *ptr &lt;&lt; std::endl; \/\/ Output: 42<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">5. Deprecated Attribute<\/h4>\n\n\n\n<p>The <code>[[deprecated]]<\/code> attribute can be used to mark functions and variables as deprecated, generating compile-time warnings when they are used.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">[[deprecated(&quot;Use new_function() instead&quot;)]]\nvoid old_function() {}\n\nvoid new_function() {}\n\nint main() {\n    old_function(); \/\/ Warning: 'old_function' is deprecated: Use new_function() instead\n    new_function();\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">6. Binary Literals and Digit Separators<\/h4>\n\n\n\n<p>C++14 introduced binary literals prefixed with <code>0b<\/code> or <code>0B<\/code> and the single quotation mark as a digit separator to improve readability of large numbers.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">int binary = 0b1010; \/\/ Binary literal\nint largeNumber = 1'000'000; \/\/ Digit separator\n\nstd::cout &lt;&lt; binary &lt;&lt; std::endl; \/\/ Output: 10\nstd::cout &lt;&lt; largeNumber &lt;&lt; std::endl; \/\/ Output: 1000000<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">C++17<\/h4>\n\n\n\n<p>C++17 brought a plethora of new features and enhancements, making the language more expressive and user-friendly. Here are some of the major additions with detailed explanations and examples:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.std::optional<\/h4>\n\n\n\n<p><code>std::optional<\/code> is a utility that represents a value that may or may not be present. It&#8217;s useful for functions that might not return a value.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;optional&gt;\n#include &lt;iostream&gt;\n\nstd::optional&lt;int&gt; find_even_number(int num) {\n    if (num % 2 == 0) return num;\n    return std::nullopt;\n}\n\nint main() {\n    auto result = find_even_number(4);\n    if (result) {\n        std::cout &lt;&lt; &quot;Even number: &quot; &lt;&lt; *result &lt;&lt; &quot;\\n&quot;;\n    } else {\n        std::cout &lt;&lt; &quot;Not an even number\\n&quot;;\n    }\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2.std::variant<\/h4>\n\n\n\n<p><code>std::variant<\/code> is a type-safe union, allowing a variable to hold one of several specified types.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;variant&gt;\n#include &lt;iostream&gt;\n\nint main() {\n    std::variant&lt;int, float, std::string&gt; my_variant;\n    my_variant = 10;\n    std::cout &lt;&lt; std::get&lt;int&gt;(my_variant) &lt;&lt; &quot;\\n&quot;;\n\n    my_variant = 3.14f;\n    std::cout &lt;&lt; std::get&lt;float&gt;(my_variant) &lt;&lt; &quot;\\n&quot;;\n\n    my_variant = &quot;Hello&quot;;\n    std::cout &lt;&lt; std::get&lt;std::string&gt;(my_variant) &lt;&lt; &quot;\\n&quot;;\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3.std::any<\/h4>\n\n\n\n<p><code>std::any<\/code> is a type-safe container for single values of any type. It&#8217;s useful when the type of the value is not known at compile time.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;any&gt;\n#include &lt;iostream&gt;\n\nint main() {\n    std::any my_any;\n    my_any = 42;\n    std::cout &lt;&lt; std::any_cast&lt;int&gt;(my_any) &lt;&lt; &quot;\\n&quot;;\n\n    my_any = std::string(&quot;Hello&quot;);\n    std::cout &lt;&lt; std::any_cast&lt;std::string&gt;(my_any) &lt;&lt; &quot;\\n&quot;;\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4. Structured Bindings<\/h4>\n\n\n\n<p>Structured bindings allow for unpacking tuple-like objects directly into individual variables.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;tuple&gt;\n#include &lt;iostream&gt;\n\nstd::tuple&lt;int, float, std::string&gt; get_data() {\n    return {1, 2.3f, &quot;test&quot;};\n}\n\nint main() {\n    auto [i, f, s] = get_data();\n    std::cout &lt;&lt; &quot;i: &quot; &lt;&lt; i &lt;&lt; &quot;, f: &quot; &lt;&lt; f &lt;&lt; &quot;, s: &quot; &lt;&lt; s &lt;&lt; &quot;\\n&quot;;\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">5.if constexpr<\/h4>\n\n\n\n<p><code>if constexpr<\/code> enables compile-time conditional compilation.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n\ntemplate &lt;typename T&gt;\nvoid print_type_info(T value) {\n    if constexpr (std::is_integral_v&lt;T&gt;) {\n        std::cout &lt;&lt; &quot;Integral type\\n&quot;;\n    } else {\n        std::cout &lt;&lt; &quot;Non-integral type\\n&quot;;\n    }\n}\n\nint main() {\n    print_type_info(42);\n    print_type_info(3.14);\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">6. Fold Expressions<\/h4>\n\n\n\n<p>Fold expressions simplify the use of variadic templates by providing a concise syntax for operations on parameter packs.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n\ntemplate&lt;typename... Args&gt;\nauto sum(Args... args) {\n    return (... + args); \/\/ fold expression\n}\n\nint main() {\n    std::cout &lt;&lt; &quot;Sum: &quot; &lt;&lt; sum(1, 2, 3, 4, 5) &lt;&lt; &quot;\\n&quot;;\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">7. Filesystem Library<\/h4>\n\n\n\n<p>The <code>&lt;filesystem&gt;<\/code> library provides facilities for performing operations on file systems and their components.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;filesystem&gt;\n#include &lt;iostream&gt;\n\nint main() {\n    std::filesystem::path p{&quot;example.txt&quot;};\n    if (std::filesystem::exists(p)) {\n        std::cout &lt;&lt; p &lt;&lt; &quot; exists\\n&quot;;\n    } else {\n        std::cout &lt;&lt; p &lt;&lt; &quot; does not exist\\n&quot;;\n    }\n}<\/pre><\/div>\n\n\n\n<p>These features collectively enhance the power and flexibility of C++, making it easier to write robust, modern, and efficient code.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">C++20<\/h4>\n\n\n\n<p>C++20 is a milestone in the evolution of C++, bringing a host of powerful features that enhance the language&#8217;s expressiveness, safety, and performance. Here\u2019s a detailed look at the major additions with examples:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Concepts<\/h4>\n\n\n\n<p>Concepts provide a way to specify constraints on template parameters, making templates more readable and error messages more understandable.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;concepts&gt;\n#include &lt;iostream&gt;\n\ntemplate &lt;typename T&gt;\nconcept Integral = std::is_integral_v&lt;T&gt;;\n\ntemplate &lt;Integral T&gt;\nT add(T a, T b) {\n    return a + b;\n}\n\nint main() {\n    std::cout &lt;&lt; add(3, 4) &lt;&lt; '\\n';  \/\/ Works\n    \/\/ std::cout &lt;&lt; add(3.0, 4.0) &lt;&lt; '\\n';  \/\/ Error: double doesn't satisfy Integral\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2. Ranges<\/h4>\n\n\n\n<p>The Ranges library introduces a new way to work with sequences of data, making code more readable and expressive.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;ranges&gt;\n#include &lt;vector&gt;\n#include &lt;iostream&gt;\n\nint main() {\n    std::vector&lt;int&gt; v = {1, 2, 3, 4, 5};\n    auto result = v | std::ranges::views::filter([](int n) { return n % 2 == 0; });\n\n    for (int n : result) {\n        std::cout &lt;&lt; n &lt;&lt; ' ';  \/\/ Output: 2 4\n    }\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. Coroutines<\/h4>\n\n\n\n<p>Coroutines allow for writing asynchronous code in a sequential style, simplifying the development of concurrent applications.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;coroutine&gt;\n#include &lt;iostream&gt;\n\nstruct ReturnObject {\n    struct promise_type {\n        ReturnObject get_return_object() { return {}; }\n        std::suspend_never initial_suspend() { return {}; }\n        std::suspend_never final_suspend() noexcept { return {}; }\n        void unhandled_exception() {}\n        void return_void() {}\n    };\n};\n\nReturnObject foo() {\n    std::cout &lt;&lt; &quot;Hello &quot;;\n    co_await std::suspend_always{};\n    std::cout &lt;&lt; &quot;World\\n&quot;;\n}\n\nint main() {\n    auto handle = foo();\n    handle.resume();\n    handle.resume();\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4. Modules<\/h4>\n\n\n\n<p>Modules provide a new way to organize and import code, improving compile times and code encapsulation.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">\/\/ my_module.ixx\nexport module my_module;\nexport int add(int a, int b) {\n    return a + b;\n}\n\n\/\/ main.cpp\nimport my_module;\n#include &lt;iostream&gt;\n\nint main() {\n    std::cout &lt;&lt; add(3, 4) &lt;&lt; '\\n';  \/\/ Output: 7\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">5. Three-way Comparison (Spaceship Operator)<\/h4>\n\n\n\n<p>The three-way comparison operator (<code>&lt;=&gt;<\/code>) simplifies the implementation of comparisons and provides a consistent way to handle them.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;compare&gt;\n#include &lt;iostream&gt;\n\nstruct Point {\n    int x, y;\n    auto operator&lt;=&gt;(const Point&amp;) const = default;\n};\n\nint main() {\n    Point p1{1, 2}, p2{2, 3};\n    if (p1 &lt; p2) {\n        std::cout &lt;&lt; &quot;p1 is less than p2\\n&quot;;  \/\/ Output\n    }\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">6. Calendar and Time Zone Library<\/h4>\n\n\n\n<p>This library provides comprehensive support for handling dates, times, and time zones.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;chrono&gt;\n#include &lt;iostream&gt;\n\nint main() {\n    using namespace std::chrono;\n    auto now = system_clock::now();\n    auto today = floor&lt;days&gt;(now);\n    std::cout &lt;&lt; &quot;Today is: &quot; &lt;&lt; today.time_since_epoch().count() &lt;&lt; &quot; days since epoch\\n&quot;;\n}<\/pre><\/div>\n\n\n\n<p>C++20 significantly enriches the language, making it more modern and powerful for a wide range of programming tasks. These features together improve the robustness, readability, and maintainability of C++ code.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">C++23<\/h4>\n\n\n\n<p>C++23 introduces several powerful features that enhance the language&#8217;s capabilities, safety, and ease of use. Here\u2019s a detailed look at some of the most significant additions:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. std::expected<\/h4>\n\n\n\n<p><code>std::expected<\/code> is a new utility for error handling, similar to <code>std::optional<\/code> but with built-in error state management.<\/p>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n#include &lt;expected&gt;\n\nstd::expected&lt;int, std::string&gt; divide(int a, int b) {\n    if (b == 0) {\n        return std::unexpected(&quot;Division by zero!&quot;);\n    }\n    return a \/ b;\n}\n\nint main() {\n    auto result = divide(10, 0);\n    if (!result) {\n        std::cout &lt;&lt; &quot;Error: &quot; &lt;&lt; result.error() &lt;&lt; '\\n';\n    } else {\n        std::cout &lt;&lt; &quot;Result: &quot; &lt;&lt; *result &lt;&lt; '\\n';\n    }\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">2.std::mdspan<\/h4>\n\n\n\n<p><code>std::mdspan<\/code> is a multi-dimensional array view, providing a way to describe the shape and layout of data in memory.<\/p>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n#include &lt;mdspan&gt;\n\nint main() {\n    int data[6] = {1, 2, 3, 4, 5, 6};\n    std::mdspan&lt;int, std::extents&lt;2, 3&gt;&gt; mdspan(data);\n    for (int i = 0; i &lt; 2; ++i) {\n        for (int j = 0; j &lt; 3; ++j) {\n            std::cout &lt;&lt; mdspan(i, j) &lt;&lt; ' ';\n        }\n        std::cout &lt;&lt; '\\n';\n    }\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">3. Reflection (Experimental)<\/h4>\n\n\n\n<p>C++23 introduces experimental reflection capabilities, allowing compile-time introspection of types and their properties.<\/p>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n#include &lt;experimental\/reflect&gt;\n\nstruct MyStruct {\n    int a;\n    double b;\n    void foo() {}\n};\n\nint main() {\n    auto type = reflexpr(MyStruct);\n    for (auto member : type.get_data_members()) {\n        std::cout &lt;&lt; &quot;Member name: &quot; &lt;&lt; member.get_name() &lt;&lt; '\\n';\n    }\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">4.if consteval<\/h4>\n\n\n\n<p>The <code>if consteval<\/code> statement allows code to check if it is being evaluated at compile-time.<\/p>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n\nconstexpr int factorial(int n) {\n    if consteval {\n        if (n &lt; 0) throw &quot;Negative input!&quot;;\n    }\n    return n &lt;= 1 ? 1 : n * factorial(n - 1);\n}\n\nint main() {\n    std::cout &lt;&lt; factorial(5) &lt;&lt; '\\n'; \/\/ OK\n    \/\/ std::cout &lt;&lt; factorial(-1) &lt;&lt; '\\n'; \/\/ Compile-time error\n}<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">5.[[assume]] Attribute<\/h4>\n\n\n\n<p>The <code>[[assume]]<\/code> attribute allows developers to provide assumptions to the optimizer, improving performance by informing the compiler about invariants.<\/p>\n\n\n\n<p><strong>Example<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n\nint main() {\n    int x = 5;\n    [[assume(x &gt; 0)]];\n    std::cout &lt;&lt; &quot;x is positive.\\n&quot;;\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>These features have significantly enhanced C++\u2019s expressiveness, safety, and performance, keeping it a robust choice for modern software development. But how many of them have you already used?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Modern C++ has seen a series of significant updates starting from C++11, each bringing new features and enhancements that aim to make the language more efficient, readable, and maintainable. Here&#8217;s a brief overview of the major features introduced in each version since C++11, along with a comment on their usage: C++11 C++11 marked a significant &hellip; <a href=\"https:\/\/cppdepend.com\/blog\/c26-is-coming-but-what-are-the-major-features-that-have-been-added-to-c-since-c11\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;C++26 is coming, but what are the major features that have been added to C++ since C++11?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[654,632,642,656,475,658,71,657,655,627,628,629,630,631,626,508,47,634,504,18,641,643,649,502,637,653,648,488,30,215,494,489,633,503,652,639,226,506,646,650,640,651,644,635,645,647,505,509,636,638,492],"class_list":["post-1809","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-assume-attribute","tag-auto-type-deduction","tag-binary-literals","tag-c-enhancements","tag-c-evolution","tag-c-improvements","tag-c-programming","tag-c-standard","tag-c-updates","tag-c11-features","tag-c14-features","tag-c17-features","tag-c20-features","tag-c23-features","tag-c26","tag-calendar-library","tag-concepts","tag-constexpr","tag-coroutines","tag-cppdepend","tag-deprecated-attribute","tag-digit-separators","tag-filesystem-library","tag-fold-expressions","tag-generic-lambdas","tag-if-consteval","tag-if-constexpr","tag-lambda-expressions","tag-modern-c","tag-modules","tag-move-semantics","tag-nullptr","tag-range-based-for-loops","tag-ranges","tag-reflection-in-c","tag-return-type-deduction","tag-smart-pointers","tag-spaceship-operator","tag-stdany","tag-stdexpected","tag-stdmake_unique","tag-stdmdspan","tag-stdoptional","tag-stdthread","tag-stdvariant","tag-structured-bindings","tag-three-way-comparison","tag-time-zone-library","tag-uniform-initialization","tag-variable-templates","tag-variadic-templates"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/comments?post=1809"}],"version-history":[{"count":7,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1809\/revisions"}],"predecessor-version":[{"id":1819,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1809\/revisions\/1819"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=1809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=1809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=1809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}