Topic: Allowing constructors to apply initializations to itself?


Author: Johannes Schaub <schaub.johannes@googlemail.com>
Date: Sun, 23 Jun 2013 05:01:35 -0700 (PDT)
Raw View
------=_Part_1884_4309308.1371988895297
Content-Type: text/plain; charset=ISO-8859-1

I was wondering whether it would make sense to allow constructors to
initializer the object itself first, before doing anything else. This
started with finding a solution for "nulling" an object. Instead of adding
in-class non-static data member initializers (leaking implementation
details possibly) or redundantly adding a member name to the
constructor-initialization-list (when it already appeared in the class
body), you could simply write

    class A {
    public:
      A():static A{} { }

    private:
      string s;
      int t;
      float u;
    };

(Thanks to Xeo for proposing "static" to abuse for this).

--

---
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_1884_4309308.1371988895297
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I was wondering whether it would make sense to allow constructors to initia=
lizer the object itself first, before doing anything else. This started wit=
h finding a solution for "nulling" an object. Instead of adding in-class no=
n-static data member initializers (leaking implementation details possibly)=
 or redundantly adding a member name to the constructor-initialization-list=
 (when it already appeared in the class body), you could simply write<div><=
br></div><div>&nbsp; &nbsp; class A {</div><div>&nbsp; &nbsp; public:</div>=
<div>&nbsp; &nbsp; &nbsp; A():static A{} { }</div><div><br></div><div>&nbsp=
; &nbsp; private:</div><div>&nbsp; &nbsp; &nbsp; string s;</div><div>&nbsp;=
 &nbsp; &nbsp; int t;</div><div>&nbsp; &nbsp; &nbsp; float u;</div><div>&nb=
sp; &nbsp; };</div><div><br></div><div>(Thanks to Xeo for proposing "static=
" to abuse for this).</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 />
&nbsp;<br />
&nbsp;<br />

------=_Part_1884_4309308.1371988895297--

.


Author: Johannes Schaub <schaub.johannes@googlemail.com>
Date: Sun, 23 Jun 2013 05:30:38 -0700 (PDT)
Raw View
------=_Part_1741_23326710.1371990638704
Content-Type: text/plain; charset=ISO-8859-1



On Sunday, June 23, 2013 2:01:35 PM UTC+2, Johannes Schaub wrote:
>
>
>
> (Thanks to Xeo for proposing "static" to abuse for this).
>

 Oops. Looks like I confused those nick names. FredOverflow proposed the
abuse: http://chat.stackoverflow.com/transcript/message/10161711#10161711

--

---
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_1741_23326710.1371990638704
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><br>On Sunday, June 23, 2013 2:01:35 PM UTC+2, Johannes Schaub wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><br><div><br></div><div>(Thanks =
to Xeo for proposing "static" to abuse for this).</div></blockquote><div><b=
r></div><div>&nbsp;Oops. Looks like I confused those nick names. FredOverfl=
ow proposed the abuse:&nbsp;<a href=3D"http://chat.stackoverflow.com/transc=
ript/message/10161711#10161711">http://chat.stackoverflow.com/transcript/me=
ssage/10161711#10161711</a></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 />
&nbsp;<br />
&nbsp;<br />

------=_Part_1741_23326710.1371990638704--

.