{"id":1971,"date":"2024-07-10T11:29:45","date_gmt":"2024-07-10T11:29:45","guid":{"rendered":"https:\/\/cppdepend.com\/blog\/?p=1971"},"modified":"2024-07-10T11:29:54","modified_gmt":"2024-07-10T11:29:54","slug":"how-advanced-c-developers-wrote-modern-code-before-the-rise-of-modern-standards","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/how-advanced-c-developers-wrote-modern-code-before-the-rise-of-modern-standards\/","title":{"rendered":"How advanced C++ developers wrote modern code before the rise of modern standards."},"content":{"rendered":"\n<p>Before the advent of C++11 and subsequent standards, advanced C++ developers had to innovate to write modern, maintainable, and efficient code. Here are some examples of how they proceeded with features that were later standardized:<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>1- shared_ptr<\/strong><\/p>\n\n\n\n<p>Smart pointers in C++ have been used for a long time, often through custom implementations or libraries like Boost. For many C++ developers, the introduction of <code>shared_ptr<\/code> and other smart pointers in the standard library was simply a way to standardize the tools they had already been using.<\/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;boost\/shared_ptr.hpp&gt;\nboost::shared_ptr&lt;int&gt; p(new int(10));<\/pre><\/div>\n\n\n\n<p><strong>2- Range based loop:<\/strong> <\/p>\n\n\n\n<p><code>BOOST_FOREACH<\/code> is a macro provided by the Boost library in C++ to simplify iterating over containers. It predates the range-based for loop introduced in C++11 and offers a way to write cleaner and more readable 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;}\">#include &lt;boost\/foreach.hpp&gt;\n#include &lt;vector&gt;\n#include &lt;iostream&gt;\n\nint main() {\n    std::vector&lt;int&gt; vec = {1, 2, 3, 4, 5};\n    BOOST_FOREACH(int&amp; x, vec) {\n        std::cout &lt;&lt; x &lt;&lt; &quot; &quot;;\n    }\n    return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>3- C++ Concepts<\/strong> <\/p>\n\n\n\n<p>Before concepts, <code>enable_if<\/code> from <code>&lt;type_traits&gt;<\/code> was used to conditionally enable function templates and class specializations based on traits. It is more verbose and harder to read, often leading to complex syntax.<\/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;\nstd::enable_if_t&lt;std::is_integral_v&lt;T&gt;, T&gt; add(T a, T b) {\n    return a + b;\n}<\/pre><\/div>\n\n\n\n<p><strong>4- Lambda Expressions:<\/strong><\/p>\n\n\n\n<p>The Boost Lambda library allows the creation of small unnamed function objects (lambdas) in C++ that can be used inline where a function object or functor is required. This is particularly useful for short operations and makes code more concise and readable.<\/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;boost\/lambda\/lambda.hpp&gt;\n#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\n#include &lt;vector&gt;\n\nint main() {\n    using namespace boost::lambda;\n    std::vector&lt;int&gt; vec = {1, 2, 3, 4, 5};\n    std::for_each(vec.begin(), vec.end(), std::cout &lt;&lt; (_1 * 2) &lt;&lt; &quot; &quot;);\n    return 0;\n}<\/pre><\/div>\n\n\n\n<p>This code prints each element of the vector multiplied by 2.<\/p>\n\n\n\n<p><strong>5- constexpr<\/strong><\/p>\n\n\n\n<p>Before <code>constexpr<\/code> was introduced in C++11, developers often relied on Boost to achieve similar compile-time constant evaluation. The Boost library offers several utilities and techniques that can help mimic the behavior of <code>constexpr<\/code>.<\/p>\n\n\n\n<p>Although not a direct replacement, <code>BOOST_STATIC_ASSERT<\/code> can be used to enforce compile-time assertions, ensuring that certain conditions are met during compilation.<\/p>\n\n\n\n<p>Example:<\/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;boost\/static_assert.hpp&gt;\n\nBOOST_STATIC_ASSERT(sizeof(int) == 4);<\/pre><\/div>\n\n\n\n<p>Boost.MPL provides also tools for compile-time computations, which can be used to achieve behavior similar to <code>constexpr<\/code> for template metaprogramming.<\/p>\n\n\n\n<p>Example:<\/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;boost\/mpl\/int.hpp&gt;\n#include &lt;boost\/mpl\/plus.hpp&gt;\n#include &lt;boost\/mpl\/equal_to.hpp&gt;\n#include &lt;boost\/static_assert.hpp&gt;\n\nnamespace mpl = boost::mpl;\n\ntypedef mpl::int_&lt;3&gt; three;\ntypedef mpl::int_&lt;4&gt; four;\ntypedef mpl::plus&lt;three, four&gt;::type seven;\n\nBOOST_STATIC_ASSERT((mpl::equal_to&lt;seven, mpl::int_&lt;7&gt;&gt;::value));<\/pre><\/div>\n\n\n\n<p>And finally Boost.Hana is a modern metaprogramming library that provides more powerful and flexible compile-time capabilities, similar to <code>constexpr<\/code>.<\/p>\n\n\n\n<p>Example:<\/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;boost\/hana.hpp&gt;\n#include &lt;iostream&gt;\n\nnamespace hana = boost::hana;\n\nconstexpr auto sum = hana::int_c&lt;3&gt; + hana::int_c&lt;4&gt;;\n\nint main() {\n    std::cout &lt;&lt; sum &lt;&lt; std::endl; \/\/ Outputs: 7\n    return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>6- Type Traits<\/strong><\/p>\n\n\n\n<p><strong>C++11<\/strong>: <code>std::is_same<\/code>, <code>std::enable_if<\/code>, etc.<br><strong>Boost<\/strong>: <code>boost::is_same<\/code>, <code>boost::enable_if<\/code>, etc.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost provided type traits and SFINAE utilities for template metaprogramming.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/type_traits.hpp&gt;\nboost::is_same&lt;int, int&gt;::value; \/\/ true<\/pre><\/div>\n\n\n\n<p><strong>7- Static Assertions<\/strong><\/p>\n\n\n\n<p><strong>C++11<\/strong>: <code>static_assert<\/code><br><strong>Boost<\/strong>: <code>BOOST_STATIC_ASSERT<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost allowed compile-time assertions to catch errors early.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/static_assert.hpp&gt;\nBOOST_STATIC_ASSERT(sizeof(int) == 4);<\/pre><\/div>\n\n\n\n<p><strong>8- Regular Expressions<\/strong><\/p>\n\n\n\n<p><strong>C++11<\/strong>: <code>std::regex<\/code><br><strong>Boost<\/strong>: <code>boost::regex<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost provided a powerful regular expression library.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/regex.hpp&gt;\nboost::regex re(&quot;^[0-9]+$&quot;);<\/pre><\/div>\n\n\n\n<p><strong>9- Tuples<\/strong><\/p>\n\n\n\n<p><strong>C++11<\/strong>: <code>std::tuple<\/code><br><strong>Boost<\/strong>: <code>boost::tuple<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost provided a way to return multiple values from a function.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/tuple\/tuple.hpp&gt;\nboost::tuple&lt;int, std::string&gt; t(1, &quot;example&quot;);<\/pre><\/div>\n\n\n\n<p><strong>10- Chrono<\/strong><\/p>\n\n\n\n<p><strong>C++11<\/strong>: <code>std::chrono<\/code><br><strong>Boost<\/strong>: <code>boost::chrono<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost provided utilities for time duration and clocks.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/chrono.hpp&gt;\nboost::chrono::steady_clock::time_point start = boost::chrono::steady_clock::now();<\/pre><\/div>\n\n\n\n<p><strong>11- Threading<\/strong><\/p>\n\n\n\n<p><strong>C++11<\/strong>: <code>std::thread<\/code><br><strong>Boost<\/strong>: <code>boost::thread<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost provided threading capabilities before it was standardized.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/thread.hpp&gt;\nboost::thread t([]{ std::cout &lt;&lt; &quot;Threading with Boost&quot;; });\nt.join();<\/pre><\/div>\n\n\n\n<p>Certainly! Here are some additional examples of how Boost provided functionality before they were standardized in C++11 and later versions:<\/p>\n\n\n\n<p><strong>12- Function Objects<\/strong><\/p>\n\n\n\n<p><strong>C++11<\/strong>: <code>std::function<\/code><br><strong>Boost<\/strong>: <code>boost::function<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost offered <code>boost::function<\/code> to store callable objects.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/function.hpp&gt;\nboost::function&lt;int(int, int)&gt; f = std::plus&lt;int&gt;();<\/pre><\/div>\n\n\n\n<p><strong>13- Bind<\/strong><\/p>\n\n\n\n<p><strong>C++11<\/strong>: <code>std::bind<\/code><br><strong>Boost<\/strong>: <code>boost::bind<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost allowed binding function arguments to create partial function applications.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/bind.hpp&gt;\nauto bound_func = boost::bind(std::plus&lt;int&gt;(), 10, _1);\nstd::cout &lt;&lt; bound_func(5); \/\/ Outputs 15<\/pre><\/div>\n\n\n\n<p><strong>14- Optional<\/strong><\/p>\n\n\n\n<p><strong>C++17<\/strong>: <code>std::optional<\/code><br><strong>Boost<\/strong>: <code>boost::optional<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost provided <code>boost::optional<\/code> for optional values, useful for functions that might not return a value.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/optional.hpp&gt;\nboost::optional&lt;int&gt; maybe_value;\nmaybe_value = 10;\nif (maybe_value) {\n    std::cout &lt;&lt; *maybe_value;\n}<\/pre><\/div>\n\n\n\n<p><strong>15- Any<\/strong><\/p>\n\n\n\n<p><strong>C++17<\/strong>: <code>std::any<\/code><br><strong>Boost<\/strong>: <code>boost::any<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost provided a type-safe container for single values of any type.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/any.hpp&gt;\nboost::any value = 10;\ntry {\n    std::cout &lt;&lt; boost::any_cast&lt;int&gt;(value);\n} catch (boost::bad_any_cast &amp;) {\n    std::cout &lt;&lt; &quot;Bad cast!&quot;;\n}<\/pre><\/div>\n\n\n\n<p><strong>16- Variant<\/strong><\/p>\n\n\n\n<p><strong>C++17<\/strong>: <code>std::variant<\/code><br><strong>Boost<\/strong>: <code>boost::variant<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost provided a type-safe union that can hold one of several types.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/variant.hpp&gt;\nboost::variant&lt;int, std::string&gt; var;\nvar = 10;\nstd::cout &lt;&lt; boost::get&lt;int&gt;(var);<\/pre><\/div>\n\n\n\n<p><strong>17- Filesystem<\/strong><\/p>\n\n\n\n<p><strong>C++17<\/strong>: <code>std::filesystem<\/code><br><strong>Boost<\/strong>: <code>boost::filesystem<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boost offered functionality for filesystem operations.<\/li>\n<\/ul>\n\n\n\n<p>Example:<\/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;boost\/filesystem.hpp&gt;\nboost::filesystem::path p(&quot;\/path\/to\/file&quot;);\nif (boost::filesystem::exists(p)) {\n    std::cout &lt;&lt; &quot;File exists.&quot;;\n}<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Boost has historically filled many gaps in the C++ standard library, providing advanced features and utilities that were later adopted by the C++ standard. These examples show how Boost helped C++ developers write more expressive and efficient code before the features were officially standardized in C++11 and later versions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before the advent of C++11 and subsequent standards, advanced C++ developers had to innovate to write modern, maintainable, and efficient code. Here are some examples of how they proceeded with features that were later standardized:<\/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":[],"class_list":["post-1971","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1971","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=1971"}],"version-history":[{"count":11,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1971\/revisions"}],"predecessor-version":[{"id":1982,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1971\/revisions\/1982"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=1971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=1971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=1971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}