{"id":4977,"date":"2016-10-11T06:13:40","date_gmt":"2016-10-11T06:13:40","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/initialization\/"},"modified":"2023-06-26T12:40:05","modified_gmt":"2023-06-26T12:40:05","slug":"initialization","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/initialization\/","title":{"rendered":"{}-Initialization"},"content":{"rendered":"<p>The initialization of variables was unified in C++11. The rule is quite simple. {}-Initialization is always applicable.&nbsp;<\/p>\n<p><!--more--><\/p>\n<h2>Always applicable<\/h2>\n<p>For simplicity reasons I will speak in the rest of the post about {}-Initialization, although I mean uniformed initialization with {}. But before I speak about two crucial implications of the {}-Initialization in safety-critical software I will show a few special use cases. This uses cases that require C++11.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ uniformInitialization.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;map&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;vector&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;string&gt;<\/span>\r\n\r\n<span style=\"color: #008000;\">\/\/ Initialization of a C-Array as attribute of a class<\/span>\r\n<span style=\"color: #0000ff;\">class<\/span> <span style=\"color: #2b91af;\">Array<\/span>{\r\n  public:\r\n    Array(): myData{1,2,3,4,5}{}    \r\n  <span style=\"color: #0000ff;\">private<\/span>:\r\n    <span style=\"color: #2b91af;\">int<\/span> myData[5];\r\n};\r\n\r\n<span style=\"color: #0000ff;\">class<\/span> <span style=\"color: #2b91af;\">MyClass<\/span>{\t\t\t\r\n  <span style=\"color: #0000ff;\">public<\/span>: \r\n    <span style=\"color: #2b91af;\">int<\/span> x;\r\n    <span style=\"color: #2b91af;\">double<\/span> y;\r\n};\r\n\r\n<span style=\"color: #0000ff;\">class<\/span> <span style=\"color: #2b91af;\">MyClass2<\/span>{\t\t\r\n  <span style=\"color: #0000ff;\">public<\/span>:\r\n    MyClass2(<span style=\"color: #2b91af;\">int<\/span> fir, <span style=\"color: #2b91af;\">double<\/span> sec):x{fir},y{sec} {};\r\n  private: \r\n    <span style=\"color: #2b91af;\">int<\/span> x;\r\n    <span style=\"color: #2b91af;\">double<\/span> y;\r\n};\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  <span style=\"color: #008000;\">\/\/ Direct Initialization of a standard container<\/span>\r\n  <span style=\"color: #2b91af;\">int<\/span> intArray[]= {1,2,3,4,5};   \r\n  std::vector&lt;<span style=\"color: #2b91af;\">int<\/span>&gt; intArray1{1,2,3,4,5};  \r\n  std::map&lt;std::string,<span style=\"color: #2b91af;\">int<\/span>&gt; myMap{{<span style=\"color: #a31515;\">\"Scott\"<\/span>,1976}, {<span style=\"color: #a31515;\">\"Dijkstra\"<\/span>,1972}};\r\n\r\n  <span style=\"color: #008000;\">\/\/ Initialization of a const heap array<\/span>\r\n  <span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #2b91af;\">float<\/span>* pData= <span style=\"color: #0000ff;\">new<\/span> <span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #2b91af;\">float<\/span>[3]{1.1,2.2,3.3};\r\n\r\n  Array arr;\r\n\r\n  <span style=\"color: #008000;\">\/\/ Defaut Initialization of a arbitrary object   <\/span>\r\n  <span style=\"color: #2b91af;\">int<\/span> i{};                <span style=\"color: #008000;\">\/\/ i becomes 0<\/span>\r\n  std::string s{};        <span style=\"color: #008000;\">\/\/ s becomes \"\"<\/span>\r\n  std::vector&lt;<span style=\"color: #2b91af;\">float<\/span>&gt; v{}; <span style=\"color: #008000;\">\/\/ v becomes an empty vector<\/span>\r\n  <span style=\"color: #2b91af;\">double<\/span> d{};             <span style=\"color: #008000;\">\/\/ d becomes 0.0<\/span>\r\n\t\r\n  <span style=\"color: #008000;\">\/\/ Initializations of an arbitrary object using public attributes\t<\/span>\r\n  MyClass myClass{2011,3.14};      \r\n  MyClass myClass1= {2011,3.14};    \r\n\r\n  <span style=\"color: #008000;\">\/\/ Initializations of an arbitrary object using the constructor<\/span>\r\n  MyClass2 myClass2{2011,3.14};     \r\n  MyClass2 myClass3= {2011,3.14};   \r\n\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>First things first. The direct initialization of the C array, the <span style=\"font-family: courier new,courier;\">std::vector,<\/span> and the <span style=\"font-family: courier new,courier;\">std::map<\/span> (lines 32 &#8211; 34) is relatively easy. In the case of the <span style=\"font-family: courier new,courier;\">std::map<\/span>, the inner {}-pairs are the key and value pairs. The following particular use case is the direct initialization of a <span style=\"font-family: courier new,courier;\">const<\/span> C array on the heap (line 36). Special about the array <span style=\"font-family: courier new,courier;\">arr <\/span>in line 39 is that C arrays can be directly initialized in the constructor initializer (line 10). The default initialization in lines 42 to 45 looks entirely innocent. But if I use round brackets instead of curly brackets, the most vexing parse will happen. That does not sound good. Why? Wait for the next section. I directly initialize in lines 48 and 49 the public attributes of the objects. It&#8217;s also possible to call the constructor with curly braces (lines 52 and 53).<\/p>\n<\/p>\n<h3>auto<\/h3>\n<p>Always applicable? Yes, but you have to keep a particular rule in mind. If you use automatic type deduction with <span style=\"font-family: courier new,courier;\">auto<\/span> in combination with an {}-initialization, you will get a <span style=\"font-family: courier new,courier;\">std::initializer_list.<\/span><\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\">  <span style=\"color: #0000ff;\">auto<\/span> initA{1};          <span style=\"color: #008000;\">\/\/ std::initializer_list&lt;int&gt;<\/span>\r\n  <span style=\"color: #0000ff;\">auto<\/span> initB= {2};        <span style=\"color: #008000;\">\/\/ std::initializer_list&lt;int&gt;<\/span>\r\n  <span style=\"color: #0000ff;\">auto<\/span> initC{1, 2};       <span style=\"color: #008000;\">\/\/ std::initializer_list&lt;int&gt;<\/span>\r\n  <span style=\"color: #0000ff;\">auto<\/span> initD= {1, 2};     <span style=\"color: #008000;\">\/\/ std::initializer_list&lt;int&gt;<br \/><\/span>\r\n<\/pre>\n<\/div>\n<p>This behavior will change very likely in C++17.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\">  <span style=\"color: #0000ff;\">auto<\/span> initA{1};          <span style=\"color: #008000;\">\/\/ int<\/span>\r\n  <span style=\"color: #0000ff;\">auto<\/span> initB= {2};        <span style=\"color: #008000;\">\/\/ std::initializer_list&lt;int&gt;<\/span>\r\n  <span style=\"color: #0000ff;\">auto<\/span> initC{1, 2};       <span style=\"color: #008000;\">\/\/ error, no single element<\/span>\r\n  <span style=\"color: #0000ff;\">auto<\/span> initD= {1, 2};     <span style=\"color: #008000;\">\/\/ std::initializer_list&lt;int&gt;<\/span>\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>I don&#8217;t like this change. The C++11 semantic is quite clear to me. I will get an initializer list if I use {}-initialization with auto. With C++17, I have to keep the two exceptions with <span style=\"font-family: courier new,courier;\">auto<\/span> in my head.<\/p>\n<ol>\n<li>It makes a difference if you use direct or copy initialization.<\/li>\n<li>It makes a difference if you use {}-initialization with one or more elements.<\/li>\n<\/ol>\n<h2>Most vexing parse<\/h2>\n<p>But what does that mean? It seems to be a well-known expression: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Most_vexing_parse\">https:\/\/en.wikipedia.org\/wiki\/Most_vexing_parse<\/a>.&nbsp; The story is quickly told. Most C++ developers know them personally. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Most_vexing_parse\"> <\/a><\/p>\n<p>At first, a small program shows the issue.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ parse.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">struct<\/span> MyInt{\r\n  MyInt(<span style=\"color: #2b91af;\">int<\/span> i):i(i){}\r\n  MyInt():i(0){}\r\n  <span style=\"color: #2b91af;\">int<\/span> i;\r\n};\r\n\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  MyInt myInt(2011);\r\n  MyInt myInt2();\r\n  \r\n  std::cout &lt;&lt; myInt.i &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; myInt2.i &lt;&lt; std::endl;\r\n \r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: courier new,courier;\">MyInt<\/span> in lines 5 &#8211; 9 is a simple wrapper for the natural number i. The constructor in line 6 sets i to an explicit value. Conversely, the default constructor in line 7 sets i to 0. So far, so good. I use both constructors in lines 14 and 15 and display the values of i. Compile and run; that&#8217;s all I have to do.<\/p>\n<p>But wait. The program does not compile.<\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4973\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/parse.png\" alt=\"parse\" width=\"700\" height=\"188\" style=\"margin: 15px;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/parse.png 795w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/parse-300x80.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/parse-768x206.png 768w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>The error message is not so meaningful. The compiler can interpret the expression in line 15 as a call of a constructor or as a declaration of a function. In case of doubt, it interprets the expression as a function declaration. The slightly modified program shows it.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ parseResolved.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;typeinfo&gt;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">struct<\/span> MyInt{\r\n  MyInt(<span style=\"color: #2b91af;\">int<\/span> i):i(i){}\r\n  MyInt():i(0){}\r\n  <span style=\"color: #2b91af;\">int<\/span> i;\r\n};\r\n\r\nMyInt myFunction();\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  MyInt myInt(2011);\r\n  MyInt myInt2();\r\n  \r\n  std::cout &lt;&lt; <span style=\"color: #0000ff;\">typeid<\/span>(myInt2).name() &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #0000ff;\">typeid<\/span>(myFunction).name() &lt;&lt; std::endl;\r\n\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>I declare in line 12 the function <span style=\"font-family: courier new,courier;\">myFunction<\/span> that has no arguments and returns a type <span style=\"font-family: courier new,courier;\">MyInt.<\/span> <span style=\"font-family: courier new,courier;\">myFunction<\/span> has the same signature as the function declarations in line 17. Thanks to the <span style=\"font-family: courier new,courier;\">typeid<\/span> operator, the program&#8217;s output shows precisely that.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4974\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/parseResolved.png\" alt=\"parseResolved\" width=\"486\" height=\"182\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/parseResolved.png 486w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/parseResolved-300x112.png 300w\" sizes=\"auto, (max-width: 486px) 100vw, 486px\" \/><\/p>\n<p>The solutions to the problem are quite easy. If I use curly braces in lines 12 and 17, the compiler will not interpret both lines as the function declaration. I already used this characteristic of the {}-initialization in the first example of this post (line 42 &#8211; 45).<\/p>\n<p>But now the main topic of this post, which is so precious for software in safety-critical systems: preventing narrowing.<\/p>\n<h2>Preventing narrowing<\/h2>\n<p>Narrowing or, more precisely, narrowing conversion is an implicit conversion of arithmetic values, including a loss of accuracy. That sounds extremely dangerous.<\/p>\n<p>The following example shows the issue with the classical initialization for fundamental types. It doesn&#8217;t matter whether I use direct initialization or assignment.<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ narrowing.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  <span style=\"color: #2b91af;\">char<\/span> c1(999);     \r\n  <span style=\"color: #2b91af;\">char<\/span> c2= 999;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"c1: \"<\/span> &lt;&lt; c1 &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"c2: \"<\/span> &lt;&lt; c2 &lt;&lt; std::endl;\r\n  \r\n  <span style=\"color: #2b91af;\">int<\/span> i1(3.14); \r\n  <span style=\"color: #2b91af;\">int<\/span> i2= 3.14;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"i1: \"<\/span> &lt;&lt; i1 &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"i2: \"<\/span> &lt;&lt; i2 &lt;&lt; std::endl;\r\n\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The output of the program shows two issues. First, the <span style=\"font-family: courier new,courier;\">int<\/span> literal 999 doesn&#8217;t fit into the type <span style=\"font-family: courier new,courier;\">char;<\/span> second, the <span style=\"font-family: courier new,courier;\">double<\/span> literal doesn&#8217;t fit into the <span style=\"font-family: courier new,courier;\">int<\/span> type.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4975\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/narrowingUndefined.png\" alt=\"narrowingUndefined\" width=\"350\" height=\"174\" style=\"margin: 15px;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/narrowingUndefined.png 400w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/narrowingUndefined-300x149.png 300w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/p>\n<p>That is not possible with {}-initialization.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ narrowingSolved.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  <span style=\"color: #2b91af;\">char<\/span> c1{999};     \r\n  <span style=\"color: #2b91af;\">char<\/span> c2= {999};\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"c1: \"<\/span> &lt;&lt; c1 &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"c2: \"<\/span> &lt;&lt; c2 &lt;&lt; std::endl;\r\n  \r\n  <span style=\"color: #2b91af;\">int<\/span> i1{3.14}; \r\n  <span style=\"color: #2b91af;\">int<\/span> i2= {3.14};\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"i1: \"<\/span> &lt;&lt; i1 &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"i2: \"<\/span> &lt;&lt; i2 &lt;&lt; std::endl;\r\n\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The program is ill-formed because of the narrowing with {}-Initialization the compiler has at least to diagnose a warning. Although the program is ill-formed, the compiler has not rejected it.<\/p>\n<p>But now, the maximum confusion with GCC begins. It makes a difference whether I use GCC 4.7 or GCC 4.8. GCC 4.7 rejected the program; GCC 4.8 only provides a warning. With GCC 5.1 we get an error. Don&#8217;t you believe me? Try it out with the online compiler <a href=\"https:\/\/gcc.godbolt.org\/\">https:\/\/gcc.godbolt.org\/<\/a>. The clang++ compiler is much more predictable. Therefore my tip. <strong>Compile your program in such a way that narrowing is an error.<\/strong> So did I. I used the flag <span style=\"font-family: courier new,courier;\">-Werror=narrowing<\/span>, and GCC 4.8 complains about the program.<\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4976\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/narrowing.png\" alt=\"narrowing\" width=\"700\" height=\"406\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/narrowing.png 753w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/narrowing-300x174.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>A small remark at the end. The expression char <span style=\"font-family: courier new,courier;\">c3{8}<\/span> is indeed no narrowing because eight fits the type char. The same holds for <span style=\"font-family: courier new,courier;\">char c3= {8}.<\/span><\/p>\n<h2>What&#8217;s next?<span style=\"font-family: courier new,courier;\"><\/span><\/h2>\n<p>C++11 got with <span style=\"font-family: courier new,courier;\">static_assert<\/span> the type-traits library two powerful features for checking the source code at compile time. In the <a href=\"https:\/\/www.modernescpp.com\/index.php\/statically-checked\">next post, <\/a>I will have a deeper look into <span style=\"font-family: courier new,courier;\">static_assert<\/span> and its combination with the functions of the type-traits library.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The initialization of variables was unified in C++11. The rule is quite simple. {}-Initialization is always applicable.&nbsp;<\/p>\n","protected":false},"author":21,"featured_media":4973,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[364],"tags":[460],"class_list":["post-4977","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded","tag-initialization"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=4977"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4977\/revisions"}],"predecessor-version":[{"id":6938,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4977\/revisions\/6938"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/4973"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=4977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=4977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=4977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}