Topic: Making a constructor an initializer list constructor explicitly


Author: Johannes Schaub <schaub.johannes@googlemail.com>
Date: Sun, 25 Aug 2013 22:48:50 -0700 (PDT)
Raw View
------=_Part_1750_32310993.1377496130100
Content-Type: text/plain; charset=ISO-8859-1

Sometimes I wonder whether one should be able to declare that one
constructor (which probably should not be declared "explicit") should not
consume braces

    struct Variant {
      Variant(std::map<int, int>);
      Variant(std::vector<string>);
    };

    Variant v{{1, 2}, {3, 4}}; // unfortunately, ill-formed!
    Variant v2{1, 2, 3}; // unfortunately, ill-formed!

It being a variant, containing the value of either a vector ("list of
ints") or a map ("map of one to another int"), I find it just intuitive
that one should be able to list initialize it with "{1, 2, 3}". However,
the constructor consomes the outer brace. I think the implication here is
that the constructor constructs a value which "wraps" something. I this
case it seems however that this makes things more complicated to the user,
since they have to remember how many braces to put.

What about making an opportunity to mark them as an initializer
constructor?

    struct Variant {
      continue Variant(std::map<int, int>);
      continue Variant(std::vector<string>);
    };

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1750_32310993.1377496130100
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sometimes I wonder whether one should be able to declare t=
hat one constructor (which probably should not be declared "explicit") shou=
ld not consume braces<div><br></div><div>&nbsp; &nbsp; struct Variant {</di=
v><div>&nbsp; &nbsp; &nbsp; Variant(std::map&lt;int, int&gt;);</div><div>&n=
bsp; &nbsp; &nbsp; Variant(std::vector&lt;string&gt;);</div><div>&nbsp; &nb=
sp; };</div><div><br></div><div>&nbsp; &nbsp; Variant v{{1, 2}, {3, 4}}; //=
 unfortunately, ill-formed!</div><div>&nbsp; &nbsp; Variant v2{1, 2, 3}; //=
 unfortunately, ill-formed!</div><div><br></div><div>It being a variant, co=
ntaining the value of either a vector ("list of ints") or a map ("map of on=
e to another int"), I find it just intuitive that one should be able to lis=
t initialize it with "{1, 2, 3}". However, the constructor consomes the out=
er brace. I think the implication here is that the constructor constructs a=
 value which "wraps" something. I this case it seems however that this make=
s things more complicated to the user, since they have to remember how many=
 braces to put.&nbsp;</div><div><br></div><div>What about making an opportu=
nity to mark them as an initializer constructor?&nbsp;</div><div><br></div>=
<div><div>&nbsp; &nbsp; struct Variant {</div><div>&nbsp; &nbsp; &nbsp; con=
tinue Variant(std::map&lt;int, int&gt;);</div><div>&nbsp; &nbsp; &nbsp; con=
tinue Variant(std::vector&lt;string&gt;);</div><div>&nbsp; &nbsp; };</div><=
/div><div><br></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1750_32310993.1377496130100--

.