<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 4, 2014 at 2:25 AM, Matt <span dir="ltr"><<a href="mailto:matdzb@gmail.com" target="_blank">matdzb@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div id=":coq" class="a3s" style="overflow:hidden">Hi!<br>
<br>
Out of curiosity, I'm wondering about the upsides/downsides of following the Scott Meyers' advice in this context.<br>
// "Develop the habit of using brace initialization without “=“.<br>
In: "Overview of the New C++ (C++11)"; <a href="http://www.aristeia.com/C++11.html" target="_blank">http://www.aristeia.com/C++11.html</a><br>
<br>
In "Uniform Initialization Syntax" he provides an example where the alternative would fail:<br>
```<br>
const float * pData = new const float[3] = { 1.f, 2.f, 3.f }; // error<br>
const float * pData = new const float[3] { 1.f, 2.f, 3.f }; // ok<br>
```<br></div></blockquote><div><br></div><div>The guidelines specifically recommend this type of thing -- here we have an aggregate being initialized in the only way that makes sense.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div id=":coq" class="a3s" style="overflow:hidden">
<br>
Similarly, another example shows that `T var = expr` syntax can’t call explicit constructors; adopting from the example (slightly simplifying, changing `Widget` to `struct`) therein:<br>
<br>
```struct Widget<br>
{<br>
        explicit Widget(int);<br>
};<br>
Widget w1(10); // okay, direct init: explicit ctor callable<br>
Widget w2{10}; // ditto<br>
Widget w3 = 10; // error! copy init: explicit ctor not callable<br>
Widget w4 = {10}; // ditto```<br>
<br>
Or, is disallowing the above the actual intent?<br></div></blockquote></div><br>Yes, disallowing this was the intent. If the constructor is 'explicit' then this is not merely converting one value to another or doing something like aggregate initialization. It is calling a very specific constructor explicitly with a specific argument. That's what it says on the tin. I would like for explicit calls to a specific constructor to look like *calls* rather than like aggregate initialization, or worse, some strange block scope. So instead, write 'Widget w1(10);' and everything is fine.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">-Chandler</div></div>