Topic: Non-member constructors


Author: Jonas Persson <l.j.persson@gmail.com>
Date: Mon, 16 Nov 2015 22:52:48 +0100
Raw View
--001a1148eb74150ade0524af6e89
Content-Type: text/plain; charset=UTF-8

After reading p0091, template deduction for constructors, and p0135, copy
elision, I have a feeling there is a proposal missing.
p0135 fixes some of the problems for factory methods for
noncopyable/nonmoveble object
and p0091 reclaim some solution space from factory functions when template
deduction is needed.

even with p0091 factory methods still has some shortcomings. The don't work
with emplace-like functions and they don't allow the user to choose if
allocation should be stack or dynamic.
p0135 isn't a general solution to factories either as it just forwards to a
concrete constructor and don't allow implementation.

In-class constructors has a few problems of their own. They tend to drag
extra dependencies into the class that is only used during construction.
Extra constructors break encapsulation. With c++11 delegating constructors
it has been more obvious that only a few constructors actually need access
to the class data.

The feature that would fix all this is the non-member constructor.
So, would they be a good idea?


  / Jonas

--

---
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/.

--001a1148eb74150ade0524af6e89
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>After reading p0091, template deduction for construct=
ors, and p0135, copy elision, I have a feeling there is a proposal missing.=
<br></div><div>p0135 fixes some of the problems for factory methods for non=
copyable/nonmoveble object</div><div>and p0091 reclaim some solution space =
from factory functions when template deduction is needed.</div><div>=C2=A0<=
/div><div>even with p0091 factory methods still has some shortcomings. The =
don&#39;t work with emplace-like functions and they don&#39;t allow the use=
r to choose if allocation should be stack or dynamic.</div><div>p0135 isn&#=
39;t a general solution to factories either as it just forwards to a concre=
te constructor and don&#39;t allow implementation.</div><div><br></div><div=
>In-class constructors has a few problems of their own. They tend to drag e=
xtra dependencies into the class that is only used during construction. Ext=
ra constructors break encapsulation. With c++11 delegating constructors it =
has been more obvious that only a few constructors actually need access to =
the class data.</div><div><br></div><div>The feature that would fix all thi=
s is the non-member constructor.</div><div>So, would they be a good idea?</=
div><div><br></div><div><br></div><div>=C2=A0 / Jonas</div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--001a1148eb74150ade0524af6e89--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Mon, 16 Nov 2015 13:57:23 -0800
Raw View
On Monday 16 November 2015 22:52:48 Jonas Persson wrote:
> The feature that would fix all this is the non-member constructor.
> So, would they be a good idea?

How is a non-member constructor different from a regular function that returns
an object of a given type?

And how do you predict the syntax using those in a new call?

 new xxxx(args);

what's xxxx for you?
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
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/.

.


Author: Jonas Persson <l.j.persson@gmail.com>
Date: Mon, 16 Nov 2015 23:19:41 +0100
Raw View
--001a1145aa8c4210b00524afceb5
Content-Type: text/plain; charset=UTF-8

On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira <thiago@macieira.org>
wrote:

> On Monday 16 November 2015 22:52:48 Jonas Persson wrote:
> > The feature that would fix all this is the non-member constructor.
> > So, would they be a good idea?
>
> How is a non-member constructor different from a regular function that
> returns
> an object of a given type?
>
> And how do you predict the syntax using those in a new call?
>
>         new xxxx(args);
>
> what's xxxx for you?

It different from a regular function in that it looks and behaves like a
constructor. There should not need to be two different ways to to do such a
basic thing as to create an object.
It might be that regular functions that returns object is the way forward,
any arguments here would be interesting to hear. The question then would be
what we need to improve to make ordinary constructors obsolete.

It probably need to be the type name, so that things like
make_shared<MyType>(arg...) work. and
std::list<MyNoCopyNoMoveType> things;
things.emplace(args);

--

---
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/.

--001a1145aa8c4210b00524afceb5
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><br></div><div class=3D"gmail_extra"><br><div class=
=3D"gmail_quote">On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira <span di=
r=3D"ltr">&lt;<a href=3D"mailto:thiago@macieira.org" target=3D"_blank">thia=
go@macieira.org</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:r=
gb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=3D"">=
On Monday 16 November 2015 22:52:48 Jonas Persson wrote:<br>
&gt; The feature that would fix all this is the non-member constructor.<br>
&gt; So, would they be a good idea?<br>
<br>
</span>How is a non-member constructor different from a regular function th=
at returns<br>
an object of a given type?<br>
<br>
And how do you predict the syntax using those in a new call?<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 new xxxx(args);<br>
<br>
what&#39;s xxxx for you?</blockquote><div>It different from a regular funct=
ion in that it looks and behaves like a constructor. There should not need =
to be two different ways to to do such a basic thing as to create an object=
..</div><div>It might be that regular functions that returns object is the w=
ay forward, any arguments here would be interesting to hear. The question t=
hen would be what we need to improve to make ordinary constructors obsolete=
..</div><div><br></div>It probably need to be the type name, so that things =
like make_shared&lt;MyType&gt;(arg...) work. and<div>std::list&lt;MyNoCopyN=
oMoveType&gt; things;=C2=A0</div><div>things.emplace(args);=C2=A0</div></di=
v><br></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--001a1145aa8c4210b00524afceb5--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Mon, 16 Nov 2015 14:36:15 -0800
Raw View
On Monday 16 November 2015 23:19:41 Jonas Persson wrote:
> On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira <thiago@macieira.org>
> wrote:
> > On Monday 16 November 2015 22:52:48 Jonas Persson wrote:
> > > The feature that would fix all this is the non-member constructor.
> > > So, would they be a good idea?
> >
> > How is a non-member constructor different from a regular function that
> > returns
> > an object of a given type?
> >
> > And how do you predict the syntax using those in a new call?
> >
> >         new xxxx(args);
> >
> > what's xxxx for you?
>
> It different from a regular function in that it looks and behaves like a
> constructor. There should not need to be two different ways to to do such a
> basic thing as to create an object.

But how? You haven't explained how it's different from a regular function.

In other words, is this a non-member constructor? If not, why not?

MyType createType(int i)
{
 MyType t;
 t.m_i = i;
 return t;
}

> It might be that regular functions that returns object is the way forward,
> any arguments here would be interesting to hear. The question then would be
> what we need to improve to make ordinary constructors obsolete.

That's never going to happen any more than regular member functions becoming
obsolete.

> It probably need to be the type name, so that things like
> make_shared<MyType>(arg...) work. and
> std::list<MyNoCopyNoMoveType> things;
> things.emplace(args);

Makes sense, but explain how that would work. How would the non-member
constructor be found? What would be the syntax?

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
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/.

.


Author: Andrey Semashev <andrey.semashev@gmail.com>
Date: Tue, 17 Nov 2015 02:14:50 +0300
Raw View
On Tue, Nov 17, 2015 at 12:52 AM, Jonas Persson <l.j.persson@gmail.com> wrote:
>
> The feature that would fix all this is the non-member constructor.
> So, would they be a good idea?

I don't think it's a good idea. Besides the syntax issue Thiago
pointed out, they would probably break encapsulation. The non-member
constructors would naturally have to have access to private and
protected members of the class (to initialize them). Then basically
any user of the class can declare a non-member constructor that has
the same access and break the class invariants by incorrect
initialization.

--

---
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/.

.


Author: Jonas Persson <l.j.persson@gmail.com>
Date: Tue, 17 Nov 2015 00:16:41 +0100
Raw View
--001a114354aa10cf2a0524b09aac
Content-Type: text/plain; charset=UTF-8

On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <thiago@macieira.org>
wrote:

> On Monday 16 November 2015 23:19:41 Jonas Persson wrote:
> > On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira <thiago@macieira.org>
> > wrote:
> > > On Monday 16 November 2015 22:52:48 Jonas Persson wrote:
> > > > The feature that would fix all this is the non-member constructor.
> > > > So, would they be a good idea?
> > >
> > > How is a non-member constructor different from a regular function that
> > > returns
> > > an object of a given type?
> > >
> > > And how do you predict the syntax using those in a new call?
> > >
> > >         new xxxx(args);
> > >
> > > what's xxxx for you?
> >
> > It different from a regular function in that it looks and behaves like a
> > constructor. There should not need to be two different ways to to do
> such a
> > basic thing as to create an object.
>
> But how? You haven't explained how it's different from a regular function.
>
> In other words, is this a non-member constructor? If not, why not?
>
> MyType createType(int i)
> {
>         MyType t;
>         t.m_i = i;
>         return t;
> }


With a named constructor you cant do a new createType();
You cant get implicit conversions.
You cant have {} initialization
You cant define copy or move constructors
You cant write generic code that construct an object T unless you know
which argument combinations need to go into T(args) and which need to go
into create<T>(arg) or whatever the factory naming convention is.


> > It might be that regular functions that returns object is the way
> forward,
> > any arguments here would be interesting to hear. The question then would
> be
> > what we need to improve to make ordinary constructors obsolete.
>
> That's never going to happen any more than regular member functions
> becoming
> obsolete.



> It probably need to be the type name, so that things like
> > make_shared<MyType>(arg...) work. and
> > std::list<MyNoCopyNoMoveType> things;
> > things.emplace(args);
>
> Makes sense, but explain how that would work. How would the non-member
> constructor be found? What would be the syntax?


The most obvious would be the same as member constructor but at namespace
scope.

Type();  // declare.
no return type and a name that matches a defined type.
Type() : Type(14) {} // define
Define as a delegating constructor that delegate to a public member
constructor in Type.

Lookup should be follow that of normal functions.

--

---
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/.

--001a114354aa10cf2a0524b09aac
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <span dir=3D"ltr">&lt=
;<a href=3D"mailto:thiago@macieira.org" target=3D"_blank">thiago@macieira.o=
rg</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D""=
>On Monday 16 November 2015 23:19:41 Jonas Persson wrote:<br>
&gt; On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira &lt;<a href=3D"mailt=
o:thiago@macieira.org">thiago@macieira.org</a>&gt;<br>
&gt; wrote:<br>
&gt; &gt; On Monday 16 November 2015 22:52:48 Jonas Persson wrote:<br>
&gt; &gt; &gt; The feature that would fix all this is the non-member constr=
uctor.<br>
&gt; &gt; &gt; So, would they be a good idea?<br>
&gt; &gt;<br>
&gt; &gt; How is a non-member constructor different from a regular function=
 that<br>
&gt; &gt; returns<br>
&gt; &gt; an object of a given type?<br>
&gt; &gt;<br>
&gt; &gt; And how do you predict the syntax using those in a new call?<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0new xxxx(args);<br>
&gt; &gt;<br>
&gt; &gt; what&#39;s xxxx for you?<br>
&gt;<br>
&gt; It different from a regular function in that it looks and behaves like=
 a<br>
&gt; constructor. There should not need to be two different ways to to do s=
uch a<br>
&gt; basic thing as to create an object.<br>
<br>
</span>But how? You haven&#39;t explained how it&#39;s different from a reg=
ular function.<br>
<br>
In other words, is this a non-member constructor? If not, why not?<br>
<br>
MyType createType(int i)<br>
{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 MyType t;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 t.m_i =3D i;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return t;<br>
<span class=3D"">}</span></blockquote><div><br></div><div>With a named cons=
tructor you cant do a new createType();</div><div>You cant get implicit con=
versions.</div><div>You cant have {} initialization</div><div>You cant defi=
ne copy or move constructors</div><div>You cant write generic code that con=
struct an object T unless you know which argument combinations need to go i=
nto T(args) and which need to go into create&lt;T&gt;(arg) or whatever the =
factory naming convention is.=C2=A0</div><div><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><span class=3D"">
<br>
&gt; It might be that regular functions that returns object is the way forw=
ard,<br>
&gt; any arguments here would be interesting to hear. The question then wou=
ld be<br>
&gt; what we need to improve to make ordinary constructors obsolete.<br>
<br>
</span>That&#39;s never going to happen any more than regular member functi=
ons becoming<br>
<span class=3D"">obsolete.</span>=C2=A0</blockquote><blockquote class=3D"gm=
ail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-le=
ft:1ex">=C2=A0</blockquote><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D"">
&gt; It probably need to be the type name, so that things like<br>
&gt; make_shared&lt;MyType&gt;(arg...) work. and<br>
&gt; std::list&lt;MyNoCopyNoMoveType&gt; things;<br>
&gt; things.emplace(args);<br>
<br>
</span>Makes sense, but explain how that would work. How would the non-memb=
er<br>
constructor be found? What would be the syntax?</blockquote><div>=C2=A0</di=
v><div>The most obvious would be the same as member constructor but at name=
space scope.</div><div><br></div><div>Type(); =C2=A0// declare.</div><div>n=
o return type and a name that matches a defined type.</div><div>Type() : Ty=
pe(14) {} // define</div><div>Define as a delegating constructor that deleg=
ate to a public member constructor in Type.</div><div><br></div><div>Lookup=
 should be follow that of normal functions.</div><div><br></div><div><br></=
div></div><br></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--001a114354aa10cf2a0524b09aac--

.


Author: Jonas Persson <l.j.persson@gmail.com>
Date: Tue, 17 Nov 2015 00:22:36 +0100
Raw View
--089e0122893c3a74790524b0af53
Content-Type: text/plain; charset=UTF-8

On Tue, Nov 17, 2015 at 12:14 AM, Andrey Semashev <andrey.semashev@gmail.com
> wrote:

> On Tue, Nov 17, 2015 at 12:52 AM, Jonas Persson <l.j.persson@gmail.com>
> wrote:
> >
> > The feature that would fix all this is the non-member constructor.
> > So, would they be a good idea?
>
> I don't think it's a good idea. Besides the syntax issue Thiago
> pointed out, they would probably break encapsulation. The non-member
> constructors would naturally have to have access to private and
> protected members of the class (to initialize them). Then basically
> any user of the class can declare a non-member constructor that has
> the same access and break the class invariants by incorrect
> initialization.
>
> One of the main reason to have non-member constructors would be that they
the will not have private access. There is no reason to have that if you
can delegate to another constructor.
Classes today often has way to many convenience constructors. That break
encapsulation. Moving them out of the class would be a big improvement.

--

---
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/.

--089e0122893c3a74790524b0af53
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Tue, Nov 17, 2015 at 12:14 AM, Andrey Semashev <span dir=3D"ltr">&lt=
;<a href=3D"mailto:andrey.semashev@gmail.com" target=3D"_blank">andrey.sema=
shev@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><spa=
n class=3D"">On Tue, Nov 17, 2015 at 12:52 AM, Jonas Persson &lt;<a href=3D=
"mailto:l.j.persson@gmail.com">l.j.persson@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; The feature that would fix all this is the non-member constructor.<br>
&gt; So, would they be a good idea?<br>
<br>
</span>I don&#39;t think it&#39;s a good idea. Besides the syntax issue Thi=
ago<br>
pointed out, they would probably break encapsulation. The non-member<br>
constructors would naturally have to have access to private and<br>
protected members of the class (to initialize them). Then basically<br>
any user of the class can declare a non-member constructor that has<br>
the same access and break the class invariants by incorrect<br>
initialization.<br>
<div class=3D"HOEnZb"><div class=3D"h5"><br></div></div></blockquote><div>O=
ne of the main reason to have non-member constructors would be that they th=
e will not have private access. There is no reason to have that if you can =
delegate to another constructor.</div><div>Classes today often has way to m=
any convenience constructors. That break encapsulation. Moving them out of =
the class would be a big improvement.</div></div><br></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--089e0122893c3a74790524b0af53--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 16 Nov 2015 17:28:22 -0800 (PST)
Raw View
------=_Part_1301_845704800.1447723702563
Content-Type: multipart/alternative;
 boundary="----=_Part_1302_191814151.1447723702564"

------=_Part_1302_191814151.1447723702564
Content-Type: text/plain; charset=UTF-8

On Monday, November 16, 2015 at 6:16:43 PM UTC-5, Jonas Persson wrote:
>
> On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <thi...@macieira.org
> <javascript:>> wrote:
>
>> On Monday 16 November 2015 23:19:41 Jonas Persson wrote:
>> > On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira <thi...@macieira.org
>> <javascript:>>
>> > wrote:
>> > > On Monday 16 November 2015 22:52:48 Jonas Persson wrote:
>> > > > The feature that would fix all this is the non-member constructor.
>> > > > So, would they be a good idea?
>> > >
>> > > How is a non-member constructor different from a regular function that
>> > > returns
>> > > an object of a given type?
>> > >
>> > > And how do you predict the syntax using those in a new call?
>> > >
>> > >         new xxxx(args);
>> > >
>> > > what's xxxx for you?
>> >
>> > It different from a regular function in that it looks and behaves like a
>> > constructor. There should not need to be two different ways to to do
>> such a
>> > basic thing as to create an object.
>>
>> But how? You haven't explained how it's different from a regular function.
>>
>> In other words, is this a non-member constructor? If not, why not?
>>
>> MyType createType(int i)
>> {
>>         MyType t;
>>         t.m_i = i;
>>         return t;
>> }
>
>
> With a named constructor you cant do a new createType();
>

.... so?


> You cant get implicit conversions.
>

That's a *good thing*. You don't want implicit conversions to be able to
happen *without* the express permission of the type in question. That is
not for external code to decide.

Having to write a function to do a conversion to another type is not a
heavy burden. I assure you that C++ is not running out of functions.

You cant have {} initialization
>

That is the closest to an actual point you've reached. And even then,
you're still ultimately inserting methods into a class definition from the
outside.

Class members are special, so they get access to special syntactic niceties.

It should be noted that the recently accepted uniform function call syntax
only works one way: syntax that looks like a global function call that
actually calls a member function. What you want is essentially the reverse:
for non-member functions to be able to be used as though they were member
functions. And that was explicitly *removed* from that proposal for various
reasons.

You cant define copy or move constructors
>

Again, that's a *good thing*. If I didn't declare a copy/move constructor,
you do not have the right to overrule that decision.

Or rather, if you want to try, you can, but only by deriving from my class
and providing your own constructors. Which you are perfectly capable of
doing.

You cant write generic code that construct an object T unless you know
> which argument combinations need to go into T(args) and which need to go
> into create<T>(arg) or whatever the factory naming convention is.
>

.... why would it need to?

If your template code wants to support arbitrary object construction, it
can declare some interface that you specialize for a type. But generally
speaking, we should not allow people to just hijack syntax away from a
class or otherwise modify the basic behavior of that class. Especially
something as important as construction.


>
>> > It might be that regular functions that returns object is the way
>> forward,
>> > any arguments here would be interesting to hear. The question then
>> would be
>> > what we need to improve to make ordinary constructors obsolete.
>>
>> That's never going to happen any more than regular member functions
>> becoming
>> obsolete.
>
>
>
> > It probably need to be the type name, so that things like
>> > make_shared<MyType>(arg...) work. and
>> > std::list<MyNoCopyNoMoveType> things;
>> > things.emplace(args);
>>
>> Makes sense, but explain how that would work. How would the non-member
>> constructor be found? What would be the syntax?
>
>
> The most obvious would be the same as member constructor but at namespace
> scope.
>
> Type();  // declare.
> no return type and a name that matches a defined type.
> Type() : Type(14) {} // define
> Define as a delegating constructor that delegate to a public member
> constructor in Type.
>
> Lookup should be follow that of normal functions.
>


--

---
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_1302_191814151.1447723702564
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Monday, November 16, 2015 at 6:16:43 PM UTC-5, Jonas Persson wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D=
"gmail_quote">On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <span dir=
=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailt=
o=3D"B0MajOEjBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascr=
ipt:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return=
 true;">thi...@macieira.org</a>&gt;</span> wrote:<br><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><span>On Monday 16 November 2015 23:19:41 Jonas Persson wrote:<br>
&gt; On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira &lt;<a href=3D"javas=
cript:" target=3D"_blank" gdf-obfuscated-mailto=3D"B0MajOEjBAAJ" rel=3D"nof=
ollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" oncli=
ck=3D"this.href=3D&#39;javascript:&#39;;return true;">thi...@macieira.org</=
a>&gt;<br>
&gt; wrote:<br>
&gt; &gt; On Monday 16 November 2015 22:52:48 Jonas Persson wrote:<br>
&gt; &gt; &gt; The feature that would fix all this is the non-member constr=
uctor.<br>
&gt; &gt; &gt; So, would they be a good idea?<br>
&gt; &gt;<br>
&gt; &gt; How is a non-member constructor different from a regular function=
 that<br>
&gt; &gt; returns<br>
&gt; &gt; an object of a given type?<br>
&gt; &gt;<br>
&gt; &gt; And how do you predict the syntax using those in a new call?<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0new xxxx(args);<br>
&gt; &gt;<br>
&gt; &gt; what&#39;s xxxx for you?<br>
&gt;<br>
&gt; It different from a regular function in that it looks and behaves like=
 a<br>
&gt; constructor. There should not need to be two different ways to to do s=
uch a<br>
&gt; basic thing as to create an object.<br>
<br>
</span>But how? You haven&#39;t explained how it&#39;s different from a reg=
ular function.<br>
<br>
In other words, is this a non-member constructor? If not, why not?<br>
<br>
MyType createType(int i)<br>
{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 MyType t;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 t.m_i =3D i;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return t;<br>
<span>}</span></blockquote><div><br></div><div>With a named constructor you=
 cant do a new createType();</div></div></div></div></blockquote><div><br>.=
... so?<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div><div class=3D"gmail_quote"><div>You cant get implicit convers=
ions.</div></div></div></div></blockquote><div><br>That&#39;s a <i>good thi=
ng</i>. You don&#39;t want implicit conversions to be able to happen <i>wit=
hout</i> the express permission of the type in question. That is not for ex=
ternal code to decide.<br><br>Having to write a function to do a conversion=
 to another type is not a heavy burden. I assure you that C++ is not runnin=
g out of functions.<br><br></div><blockquote class=3D"gmail_quote" style=3D=
"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex=
;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>You cant have {} i=
nitialization</div></div></div></div></blockquote><div><br>That is the clos=
est to an actual point you&#39;ve reached. And even then, you&#39;re still =
ultimately inserting methods into a class definition from the outside.<br><=
br>Class members are special, so they get access to special syntactic nicet=
ies.<br><br>It should be noted that the recently accepted uniform function =
call=20
syntax only works one way: syntax that looks like a global function call
 that actually calls a member function. What you want is essentially the
 reverse: for non-member functions to be able to be used as though they=20
were member functions. And that was explicitly <i>removed</i> from that pro=
posal for various reasons.<br><br></div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-le=
ft: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>You cant de=
fine copy or move constructors</div></div></div></div></blockquote><div><br=
>Again, that&#39;s a <i>good thing</i>. If I didn&#39;t declare a copy/move=
 constructor, you do not have the right to overrule that decision.<br><br>O=
r rather, if you want to try, you can, but only by deriving from my class a=
nd providing your own constructors. Which you are perfectly capable of doin=
g.<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r"><div><div class=3D"gmail_quote"><div>You cant write generic code that co=
nstruct an object T unless you know which argument combinations need to go =
into T(args) and which need to go into create&lt;T&gt;(arg) or whatever the=
 factory naming convention is.</div></div></div></div></blockquote><div><br=
>... why would it need to?<br><br>If your template code wants to support ar=
bitrary object construction, it can declare some interface that you special=
ize for a type. But generally speaking, we should not allow people to just =
hijack syntax away from a class or otherwise modify the basic behavior of t=
hat class. Especially something as important as construction.<br><br></div>=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div cla=
ss=3D"gmail_quote"><div><br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>
<br>
&gt; It might be that regular functions that returns object is the way forw=
ard,<br>
&gt; any arguments here would be interesting to hear. The question then wou=
ld be<br>
&gt; what we need to improve to make ordinary constructors obsolete.<br>
<br>
</span>That&#39;s never going to happen any more than regular member functi=
ons becoming<br>
<span>obsolete.</span>=C2=A0</blockquote><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=C2=
=A0</blockquote><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8e=
x;border-left:1px #ccc solid;padding-left:1ex"><span>
&gt; It probably need to be the type name, so that things like<br>
&gt; make_shared&lt;MyType&gt;(arg...) work. and<br>
&gt; std::list&lt;MyNoCopyNoMoveType&gt; things;<br>
&gt; things.emplace(args);<br>
<br>
</span>Makes sense, but explain how that would work. How would the non-memb=
er<br>
constructor be found? What would be the syntax?</blockquote><div>=C2=A0</di=
v><div>The most obvious would be the same as member constructor but at name=
space scope.</div><div><br></div><div>Type(); =C2=A0// declare.</div><div>n=
o return type and a name that matches a defined type.</div><div>Type() : Ty=
pe(14) {} // define</div><div>Define as a delegating constructor that deleg=
ate to a public member constructor in Type.</div><div><br></div><div>Lookup=
 should be follow that of normal functions.<br></div></div></div></div></bl=
ockquote><div><br><br></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_1302_191814151.1447723702564--
------=_Part_1301_845704800.1447723702563--

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Mon, 16 Nov 2015 18:06:44 -0800
Raw View
--001a1143a0f43bfd470524b2fa51
Content-Type: text/plain; charset=UTF-8

On Mon, Nov 16, 2015 at 5:28 PM, Nicol Bolas <jmckesson@gmail.com> wrote:

> On Monday, November 16, 2015 at 6:16:43 PM UTC-5, Jonas Persson wrote:
>>
>> On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <thi...@macieira.org>
>> wrote:
>>
>>> On Monday 16 November 2015 23:19:41 Jonas Persson wrote:
>>> > On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira <thi...@macieira.org
>>> >
>>> > wrote:
>>> > > On Monday 16 November 2015 22:52:48 Jonas Persson wrote:
>>> > > > The feature that would fix all this is the non-member constructor.
>>> > > > So, would they be a good idea?
>>> > >
>>> > > How is a non-member constructor different from a regular function
>>> that
>>> > > returns
>>> > > an object of a given type?
>>> > >
>>> > > And how do you predict the syntax using those in a new call?
>>> > >
>>> > >         new xxxx(args);
>>> > >
>>> > > what's xxxx for you?
>>> >
>>> > It different from a regular function in that it looks and behaves like
>>> a
>>> > constructor. There should not need to be two different ways to to do
>>> such a
>>> > basic thing as to create an object.
>>>
>>> But how? You haven't explained how it's different from a regular
>>> function.
>>>
>>> In other words, is this a non-member constructor? If not, why not?
>>>
>>> MyType createType(int i)
>>> {
>>>         MyType t;
>>>         t.m_i = i;
>>>         return t;
>>> }
>>
>>
>> With a named constructor you cant do a new createType();
>>
>
> ... so?
>

With P0135, we can have factory functions that return nonmoveable types. It
would be useful to be able to construct such returned objects on the heap.
However, while you can't use 'new createType()', you may be able to use
'new auto(createType())'.

You cant get implicit conversions.
>>
>
> That's a *good thing*. You don't want implicit conversions to be able to
> happen *without* the express permission of the type in question. That is
> not for external code to decide.
>
> Having to write a function to do a conversion to another type is not a
> heavy burden. I assure you that C++ is not running out of functions.
>
> You cant have {} initialization
>>
>
> That is the closest to an actual point you've reached. And even then,
> you're still ultimately inserting methods into a class definition from the
> outside.
>
> Class members are special, so they get access to special syntactic
> niceties.
>
> It should be noted that the recently accepted uniform function call syntax
> only works one way: syntax that looks like a global function call that
> actually calls a member function. What you want is essentially the reverse:
> for non-member functions to be able to be used as though they were member
> functions. And that was explicitly *removed* from that proposal for
> various reasons.
>
> You cant define copy or move constructors
>>
>
> Again, that's a *good thing*. If I didn't declare a copy/move
> constructor, you do not have the right to overrule that decision.
>
> Or rather, if you want to try, you can, but only by deriving from my class
> and providing your own constructors. Which you are perfectly capable of
> doing.
>
> You cant write generic code that construct an object T unless you know
>> which argument combinations need to go into T(args) and which need to go
>> into create<T>(arg) or whatever the factory naming convention is.
>>
>
> ... why would it need to?
>
> If your template code wants to support arbitrary object construction, it
> can declare some interface that you specialize for a type. But generally
> speaking, we should not allow people to just hijack syntax away from a
> class or otherwise modify the basic behavior of that class. Especially
> something as important as construction.
>
>
>>
>>> > It might be that regular functions that returns object is the way
>>> forward,
>>> > any arguments here would be interesting to hear. The question then
>>> would be
>>> > what we need to improve to make ordinary constructors obsolete.
>>>
>>> That's never going to happen any more than regular member functions
>>> becoming
>>> obsolete.
>>
>>
>>
>> > It probably need to be the type name, so that things like
>>> > make_shared<MyType>(arg...) work. and
>>> > std::list<MyNoCopyNoMoveType> things;
>>> > things.emplace(args);
>>>
>>> Makes sense, but explain how that would work. How would the non-member
>>> constructor be found? What would be the syntax?
>>
>>
>> The most obvious would be the same as member constructor but at namespace
>> scope.
>>
>> Type();  // declare.
>> no return type and a name that matches a defined type.
>> Type() : Type(14) {} // define
>> Define as a delegating constructor that delegate to a public member
>> constructor in Type.
>>
>> Lookup should be follow that of normal functions.
>>
>
>
> --
>
> ---
> 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/.
>

--

---
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/.

--001a1143a0f43bfd470524b2fa51
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On M=
on, Nov 16, 2015 at 5:28 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a href=3D"m=
ailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>&gt;</s=
pan> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex">On Monday, November 16, 2015 =
at 6:16:43 PM UTC-5, Jonas Persson wrote:<blockquote class=3D"gmail_quote" =
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><span class=3D"">On =
Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <span dir=3D"ltr">&lt;<a rel=
=3D"nofollow">thi...@macieira.org</a>&gt;</span> wrote:<br></span><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex"><span><span class=3D"">On Monday 16 November 2015 23:=
19:41 Jonas Persson wrote:<br></span>
&gt; On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira &lt;<a rel=3D"nofoll=
ow">thi...@macieira.org</a>&gt;<span class=3D""><br>
&gt; wrote:<br>
&gt; &gt; On Monday 16 November 2015 22:52:48 Jonas Persson wrote:<br>
&gt; &gt; &gt; The feature that would fix all this is the non-member constr=
uctor.<br>
&gt; &gt; &gt; So, would they be a good idea?<br>
&gt; &gt;<br>
&gt; &gt; How is a non-member constructor different from a regular function=
 that<br>
&gt; &gt; returns<br>
&gt; &gt; an object of a given type?<br>
&gt; &gt;<br>
&gt; &gt; And how do you predict the syntax using those in a new call?<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0new xxxx(args);<br>
&gt; &gt;<br>
&gt; &gt; what&#39;s xxxx for you?<br>
&gt;<br>
&gt; It different from a regular function in that it looks and behaves like=
 a<br>
&gt; constructor. There should not need to be two different ways to to do s=
uch a<br>
&gt; basic thing as to create an object.<br>
<br>
</span></span><span class=3D"">But how? You haven&#39;t explained how it&#3=
9;s different from a regular function.<br>
<br>
In other words, is this a non-member constructor? If not, why not?<br>
<br>
MyType createType(int i)<br>
{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 MyType t;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 t.m_i =3D i;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return t;<br>
<span>}</span></span></blockquote><span class=3D""><div><br></div><div>With=
 a named constructor you cant do a new createType();</div></span></div></di=
v></div></blockquote><div><br>... so?<br></div></blockquote><div><br></div>=
<div>With P0135, we can have factory functions that return nonmoveable type=
s. It would be useful to be able to construct such returned objects on the =
heap. However, while you can&#39;t use &#39;new createType()&#39;, you may =
be able to use &#39;new auto(createType())&#39;.</div><div><br></div><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
 solid;padding-left:1ex"><div></div><span class=3D""><blockquote class=3D"g=
mail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>You=
 cant get implicit conversions.</div></div></div></div></blockquote></span>=
<div><br>That&#39;s a <i>good thing</i>. You don&#39;t want implicit conver=
sions to be able to happen <i>without</i> the express permission of the typ=
e in question. That is not for external code to decide.<br><br>Having to wr=
ite a function to do a conversion to another type is not a heavy burden. I =
assure you that C++ is not running out of functions.<br><br></div><blockquo=
te class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_qu=
ote"><div>You cant have {} initialization</div></div></div></div></blockquo=
te><div><br>That is the closest to an actual point you&#39;ve reached. And =
even then, you&#39;re still ultimately inserting methods into a class defin=
ition from the outside.<br><br>Class members are special, so they get acces=
s to special syntactic niceties.<br><br>It should be noted that the recentl=
y accepted uniform function call=20
syntax only works one way: syntax that looks like a global function call
 that actually calls a member function. What you want is essentially the
 reverse: for non-member functions to be able to be used as though they=20
were member functions. And that was explicitly <i>removed</i> from that pro=
posal for various reasons.<br><br></div><span class=3D""><blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><di=
v>You cant define copy or move constructors</div></div></div></div></blockq=
uote></span><div><br>Again, that&#39;s a <i>good thing</i>. If I didn&#39;t=
 declare a copy/move constructor, you do not have the right to overrule tha=
t decision.<br><br>Or rather, if you want to try, you can, but only by deri=
ving from my class and providing your own constructors. Which you are perfe=
ctly capable of doing.<br><br></div><span class=3D""><blockquote class=3D"g=
mail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>You=
 cant write generic code that construct an object T unless you know which a=
rgument combinations need to go into T(args) and which need to go into crea=
te&lt;T&gt;(arg) or whatever the factory naming convention is.</div></div><=
/div></div></blockquote></span><div><br>... why would it need to?<br><br>If=
 your template code wants to support arbitrary object construction, it can =
declare some interface that you specialize for a type. But generally speaki=
ng, we should not allow people to just hijack syntax away from a class or o=
therwise modify the basic behavior of that class. Especially something as i=
mportant as construction.<br><br></div><div class=3D"HOEnZb"><div class=3D"=
h5"><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div clas=
s=3D"gmail_quote"><div><br></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>
<br>
&gt; It might be that regular functions that returns object is the way forw=
ard,<br>
&gt; any arguments here would be interesting to hear. The question then wou=
ld be<br>
&gt; what we need to improve to make ordinary constructors obsolete.<br>
<br>
</span>That&#39;s never going to happen any more than regular member functi=
ons becoming<br>
<span>obsolete.</span>=C2=A0</blockquote><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=C2=
=A0</blockquote><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8e=
x;border-left:1px #ccc solid;padding-left:1ex"><span>
&gt; It probably need to be the type name, so that things like<br>
&gt; make_shared&lt;MyType&gt;(arg...) work. and<br>
&gt; std::list&lt;MyNoCopyNoMoveType&gt; things;<br>
&gt; things.emplace(args);<br>
<br>
</span>Makes sense, but explain how that would work. How would the non-memb=
er<br>
constructor be found? What would be the syntax?</blockquote><div>=C2=A0</di=
v><div>The most obvious would be the same as member constructor but at name=
space scope.</div><div><br></div><div>Type(); =C2=A0// declare.</div><div>n=
o return type and a name that matches a defined type.</div><div>Type() : Ty=
pe(14) {} // define</div><div>Define as a delegating constructor that deleg=
ate to a public member constructor in Type.</div><div><br></div><div>Lookup=
 should be follow that of normal functions.<br></div></div></div></div></bl=
ockquote><div><br><br></div>

<p></p>

-- <br>
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--001a1143a0f43bfd470524b2fa51--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 16 Nov 2015 18:24:48 -0800 (PST)
Raw View
------=_Part_1343_1759713293.1447727088340
Content-Type: multipart/alternative;
 boundary="----=_Part_1344_1959297776.1447727088340"

------=_Part_1344_1959297776.1447727088340
Content-Type: text/plain; charset=UTF-8

On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:
>
> On Mon, Nov 16, 2015 at 5:28 PM, Nicol Bolas <jmck...@gmail.com
> <javascript:>> wrote:
>
>> On Monday, November 16, 2015 at 6:16:43 PM UTC-5, Jonas Persson wrote:
>>>
>>> On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <thi...@macieira.org>
>>> wrote:
>>>
>>>> On Monday 16 November 2015 23:19:41 Jonas Persson wrote:
>>>> > On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira <
>>>> thi...@macieira.org>
>>>> > wrote:
>>>> > > On Monday 16 November 2015 22:52:48 Jonas Persson wrote:
>>>> > > > The feature that would fix all this is the non-member constructor.
>>>> > > > So, would they be a good idea?
>>>> > >
>>>> > > How is a non-member constructor different from a regular function
>>>> that
>>>> > > returns
>>>> > > an object of a given type?
>>>> > >
>>>> > > And how do you predict the syntax using those in a new call?
>>>> > >
>>>> > >         new xxxx(args);
>>>> > >
>>>> > > what's xxxx for you?
>>>> >
>>>> > It different from a regular function in that it looks and behaves
>>>> like a
>>>> > constructor. There should not need to be two different ways to to do
>>>> such a
>>>> > basic thing as to create an object.
>>>>
>>>> But how? You haven't explained how it's different from a regular
>>>> function.
>>>>
>>>> In other words, is this a non-member constructor? If not, why not?
>>>>
>>>> MyType createType(int i)
>>>> {
>>>>         MyType t;
>>>>         t.m_i = i;
>>>>         return t;
>>>> }
>>>
>>>
>>> With a named constructor you cant do a new createType();
>>>
>>
>> ... so?
>>
>
> With P0135, we can have factory functions that return nonmoveable types.
> It would be useful to be able to construct such returned objects on the
> heap. However, while you can't use 'new createType()', you may be able to
> use 'new auto(createType())'.
>

And what exactly does this do? Allocate memory and pass that as the return
value? I'd much rather have a more general syntax for something like that,
so that you could use a user-provided buffer rather than only what
`operator new` returns.

--

---
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_1344_1959297776.1447727088340
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D=
"gmail_quote">On Mon, Nov 16, 2015 at 5:28 PM, Nicol Bolas <span dir=3D"ltr=
">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"SH=
DIZSktBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#3=
9;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;"=
>jmck...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
On Monday, November 16, 2015 at 6:16:43 PM UTC-5, Jonas Persson wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmai=
l_quote"><span>On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <span dir=
=3D"ltr">&lt;<a rel=3D"nofollow">thi...@macieira.org</a>&gt;</span> wrote:<=
br></span><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bord=
er-left:1px #ccc solid;padding-left:1ex"><span><span>On Monday 16 November =
2015 23:19:41 Jonas Persson wrote:<br></span>
&gt; On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira &lt;<a rel=3D"nofoll=
ow">thi...@macieira.org</a>&gt;<span><br>
&gt; wrote:<br>
&gt; &gt; On Monday 16 November 2015 22:52:48 Jonas Persson wrote:<br>
&gt; &gt; &gt; The feature that would fix all this is the non-member constr=
uctor.<br>
&gt; &gt; &gt; So, would they be a good idea?<br>
&gt; &gt;<br>
&gt; &gt; How is a non-member constructor different from a regular function=
 that<br>
&gt; &gt; returns<br>
&gt; &gt; an object of a given type?<br>
&gt; &gt;<br>
&gt; &gt; And how do you predict the syntax using those in a new call?<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0new xxxx(args);<br>
&gt; &gt;<br>
&gt; &gt; what&#39;s xxxx for you?<br>
&gt;<br>
&gt; It different from a regular function in that it looks and behaves like=
 a<br>
&gt; constructor. There should not need to be two different ways to to do s=
uch a<br>
&gt; basic thing as to create an object.<br>
<br>
</span></span><span>But how? You haven&#39;t explained how it&#39;s differe=
nt from a regular function.<br>
<br>
In other words, is this a non-member constructor? If not, why not?<br>
<br>
MyType createType(int i)<br>
{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 MyType t;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 t.m_i =3D i;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return t;<br>
<span>}</span></span></blockquote><span><div><br></div><div>With a named co=
nstructor you cant do a new createType();</div></span></div></div></div></b=
lockquote><div><br>... so?<br></div></blockquote><div><br></div><div>With P=
0135, we can have factory functions that return nonmoveable types. It would=
 be useful to be able to construct such returned objects on the heap. Howev=
er, while you can&#39;t use &#39;new createType()&#39;, you may be able to =
use &#39;new auto(createType())&#39;.</div></div></div></div></blockquote><=
br>And what exactly does this do? Allocate memory and pass that as the retu=
rn value? I&#39;d much rather have a more general syntax for something like=
 that, so that you could use a user-provided buffer rather than only what `=
operator new` returns.<br>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_1344_1959297776.1447727088340--
------=_Part_1343_1759713293.1447727088340--

.


Author: Jonas Persson <l.j.persson@gmail.com>
Date: Tue, 17 Nov 2015 09:26:12 +0100
Raw View
--001a11478ae051a1810524b847a0
Content-Type: text/plain; charset=UTF-8

On Tue, Nov 17, 2015 at 12:16 AM, Jonas Persson <l.j.persson@gmail.com>
wrote:

>
>
> On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <thiago@macieira.org>
> wrote:
>
>> Makes sense, but explain how that would work. How would the non-member
>>
> constructor be found? What would be the syntax?
>
>
> Type() : Type(14) {} // define
> Define as a delegating constructor that delegate to a public member
> constructor in Type.
>

After sleeping a few hours on this I remebered that the my initial thought
when reading p0091 & p0135 was that they should be combined
into factory functions
auto Type() -> Type {}
where the function body is restricted to imlementations that can do copy
elison. This would be a better aproach, I think.

 / Jonas

--

---
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/.

--001a11478ae051a1810524b847a0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Tue, Nov 17, 2015 at 12:16 AM, Jonas Persson <span dir=3D"ltr">&lt;<=
a href=3D"mailto:l.j.persson@gmail.com" target=3D"_blank">l.j.persson@gmail=
..com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"lt=
r"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quote"><span clas=
s=3D"">On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <span dir=3D"ltr">=
&lt;<a href=3D"mailto:thiago@macieira.org" target=3D"_blank">thiago@macieir=
a.org</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Makes sense, =
but explain how that would work. How would the non-member<br></blockquote><=
/span><span class=3D""><blockquote class=3D"gmail_quote" style=3D"margin:0 =
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
constructor be found? What would be the syntax?</blockquote><div>=C2=A0</di=
v></span><div>Type() : Type(14) {} // define<br></div><div>Define as a dele=
gating constructor that delegate to a public member constructor in Type.</d=
iv></div></div></div></blockquote><div>=C2=A0</div><div>After sleeping a fe=
w hours on this I remebered that the my initial thought when reading p0091 =
&amp; p0135 was that they should be combined</div><div>into factory functio=
ns=C2=A0</div><div>auto Type() -&gt; Type {}</div><div>where the function b=
ody is restricted to imlementations that can do copy elison. This would be =
a better aproach, I think.</div><div><br></div><div>=C2=A0/ Jonas</div></di=
v></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--001a11478ae051a1810524b847a0--

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 17 Nov 2015 16:17:56 -0800
Raw View
--001a114d7ec8f56b550524c592f6
Content-Type: text/plain; charset=UTF-8

On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <jmckesson@gmail.com> wrote:

> On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:
>
>> On Mon, Nov 16, 2015 at 5:28 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>>
>>> On Monday, November 16, 2015 at 6:16:43 PM UTC-5, Jonas Persson wrote:
>>>>
>>>> On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macieira <thi...@macieira.org>
>>>> wrote:
>>>>
>>>>> On Monday 16 November 2015 23:19:41 Jonas Persson wrote:
>>>>> > On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira <
>>>>> thi...@macieira.org>
>>>>> > wrote:
>>>>> > > On Monday 16 November 2015 22:52:48 Jonas Persson wrote:
>>>>> > > > The feature that would fix all this is the non-member
>>>>> constructor.
>>>>> > > > So, would they be a good idea?
>>>>> > >
>>>>> > > How is a non-member constructor different from a regular function
>>>>> that
>>>>> > > returns
>>>>> > > an object of a given type?
>>>>> > >
>>>>> > > And how do you predict the syntax using those in a new call?
>>>>> > >
>>>>> > >         new xxxx(args);
>>>>> > >
>>>>> > > what's xxxx for you?
>>>>> >
>>>>> > It different from a regular function in that it looks and behaves
>>>>> like a
>>>>> > constructor. There should not need to be two different ways to to do
>>>>> such a
>>>>> > basic thing as to create an object.
>>>>>
>>>>> But how? You haven't explained how it's different from a regular
>>>>> function.
>>>>>
>>>>> In other words, is this a non-member constructor? If not, why not?
>>>>>
>>>>> MyType createType(int i)
>>>>> {
>>>>>         MyType t;
>>>>>         t.m_i = i;
>>>>>         return t;
>>>>> }
>>>>
>>>>
>>>> With a named constructor you cant do a new createType();
>>>>
>>>
>>> ... so?
>>>
>>
>> With P0135, we can have factory functions that return nonmoveable types.
>> It would be useful to be able to construct such returned objects on the
>> heap. However, while you can't use 'new createType()', you may be able to
>> use 'new auto(createType())'.
>>
>
> And what exactly does this do? Allocate memory and pass that as the return
> value? I'd much rather have a more general syntax for something like that,
> so that you could use a user-provided buffer rather than only what
> `operator new` returns.


That's what placement new is for?

--

---
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/.

--001a114d7ec8f56b550524c592f6
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On M=
on, Nov 16, 2015 at 6:24 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a href=3D"m=
ailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>&gt;</s=
pan> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex">On Monday, November 16, 2015 =
at 9:06:48 PM UTC-5, Richard Smith wrote:<div><div class=3D"h5"><blockquote=
 class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px =
#ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quot=
e">On Mon, Nov 16, 2015 at 5:28 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a re=
l=3D"nofollow">jmck...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">On Monday, November 16, 2015 at 6:16:43 PM UTC-5, Jonas Perss=
on wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.=
8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div=
 class=3D"gmail_quote"><span>On Mon, Nov 16, 2015 at 11:36 PM, Thiago Macie=
ira <span dir=3D"ltr">&lt;<a rel=3D"nofollow">thi...@macieira.org</a>&gt;</=
span> wrote:<br></span><blockquote class=3D"gmail_quote" style=3D"margin:0 =
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><span>On Monday=
 16 November 2015 23:19:41 Jonas Persson wrote:<br></span>
&gt; On Mon, Nov 16, 2015 at 10:57 PM, Thiago Macieira &lt;<a rel=3D"nofoll=
ow">thi...@macieira.org</a>&gt;<span><br>
&gt; wrote:<br>
&gt; &gt; On Monday 16 November 2015 22:52:48 Jonas Persson wrote:<br>
&gt; &gt; &gt; The feature that would fix all this is the non-member constr=
uctor.<br>
&gt; &gt; &gt; So, would they be a good idea?<br>
&gt; &gt;<br>
&gt; &gt; How is a non-member constructor different from a regular function=
 that<br>
&gt; &gt; returns<br>
&gt; &gt; an object of a given type?<br>
&gt; &gt;<br>
&gt; &gt; And how do you predict the syntax using those in a new call?<br>
&gt; &gt;<br>
&gt; &gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0new xxxx(args);<br>
&gt; &gt;<br>
&gt; &gt; what&#39;s xxxx for you?<br>
&gt;<br>
&gt; It different from a regular function in that it looks and behaves like=
 a<br>
&gt; constructor. There should not need to be two different ways to to do s=
uch a<br>
&gt; basic thing as to create an object.<br>
<br>
</span></span><span>But how? You haven&#39;t explained how it&#39;s differe=
nt from a regular function.<br>
<br>
In other words, is this a non-member constructor? If not, why not?<br>
<br>
MyType createType(int i)<br>
{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 MyType t;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 t.m_i =3D i;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return t;<br>
<span>}</span></span></blockquote><span><div><br></div><div>With a named co=
nstructor you cant do a new createType();</div></span></div></div></div></b=
lockquote><div><br>... so?<br></div></blockquote><div><br></div><div>With P=
0135, we can have factory functions that return nonmoveable types. It would=
 be useful to be able to construct such returned objects on the heap. Howev=
er, while you can&#39;t use &#39;new createType()&#39;, you may be able to =
use &#39;new auto(createType())&#39;.</div></div></div></div></blockquote><=
br></div></div>And what exactly does this do? Allocate memory and pass that=
 as the return value? I&#39;d much rather have a more general syntax for so=
mething like that, so that you could use a user-provided buffer rather than=
 only what `operator new` returns.</blockquote><div><br></div><div>That&#39=
;s what placement new is for?=C2=A0</div></div></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--001a114d7ec8f56b550524c592f6--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 17 Nov 2015 16:47:21 -0800 (PST)
Raw View
------=_Part_4207_919040612.1447807641686
Content-Type: multipart/alternative;
 boundary="----=_Part_4208_1977924734.1447807641686"

------=_Part_4208_1977924734.1447807641686
Content-Type: text/plain; charset=UTF-8

On Tuesday, November 17, 2015 at 7:17:58 PM UTC-5, Richard Smith wrote:
>
> On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <jmck...@gmail.com
> <javascript:>> wrote:
>
>> On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:
>>
>>> With P0135, we can have factory functions that return nonmoveable types.
>>> It would be useful to be able to construct such returned objects on the
>>> heap. However, while you can't use 'new createType()', you may be able to
>>> use 'new auto(createType())'.
>>>
>>
>> And what exactly does this do? Allocate memory and pass that as the
>> return value? I'd much rather have a more general syntax for something like
>> that, so that you could use a user-provided buffer rather than only what
>> `operator new` returns.
>
>
> That's what placement new is for?
>

So something like `new(data) auto(createType())`?

In any case, I think I have a better solution. Just make P0135 do what
you're asking for.

That is, add wording to P0135 that allows `new TypeName(function(...))` to
elide the move completely. This would mean that, if `TypeName` is an exact
match to the return value of `function(...)`, then the compiler will
allocate the memory (or use placement syntax to get it), then pass that
memory as the return value to `function`, which will initialize it.

This way, you don't need new syntax.

--

---
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_4208_1977924734.1447807641686
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 17, 2015 at 7:17:58 PM UTC-5, Richard Smith wrote:<blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=
=3D"gmail_quote">On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <span dir=3D"=
ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D=
"ojzIt811BAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:=
&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return tru=
e;">jmck...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x">On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:<d=
iv><div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div =
class=3D"gmail_quote"><div></div><div>With P0135, we can have factory funct=
ions that return nonmoveable types. It would be useful to be able to constr=
uct such returned objects on the heap. However, while you can&#39;t use &#3=
9;new createType()&#39;, you may be able to use &#39;new auto(createType())=
&#39;.</div></div></div></div></blockquote><br></div></div>And what exactly=
 does this do? Allocate memory and pass that as the return value? I&#39;d m=
uch rather have a more general syntax for something like that, so that you =
could use a user-provided buffer rather than only what `operator new` retur=
ns.</blockquote><div><br></div><div>That&#39;s what placement new is for?=
=C2=A0</div></div></div></div></blockquote><div><br>So something like `new(=
data) auto(createType())`?<br><br>In any case, I think I have a better solu=
tion. Just make P0135 do what you&#39;re asking for.<br><br>That is, add wo=
rding to P0135 that allows `new TypeName(function(...))` to elide the move =
completely. This would mean that, if `TypeName` is an exact match to the re=
turn value of `function(...)`, then the compiler will allocate the memory (=
or use placement syntax to get it), then pass that memory as the return val=
ue to `function`, which will initialize it.<br><br>This way, you don&#39;t =
need new syntax.<br></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_4208_1977924734.1447807641686--
------=_Part_4207_919040612.1447807641686--

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 17 Nov 2015 17:24:26 -0800
Raw View
--001a1140c11ad2fad10524c680a4
Content-Type: text/plain; charset=UTF-8

On Tue, Nov 17, 2015 at 4:47 PM, Nicol Bolas <jmckesson@gmail.com> wrote:

> On Tuesday, November 17, 2015 at 7:17:58 PM UTC-5, Richard Smith wrote:
>>
>> On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>>
>>> On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:
>>>
>>>> With P0135, we can have factory functions that return nonmoveable
>>>> types. It would be useful to be able to construct such returned objects on
>>>> the heap. However, while you can't use 'new createType()', you may be able
>>>> to use 'new auto(createType())'.
>>>>
>>>
>>> And what exactly does this do? Allocate memory and pass that as the
>>> return value? I'd much rather have a more general syntax for something like
>>> that, so that you could use a user-provided buffer rather than only what
>>> `operator new` returns.
>>
>>
>> That's what placement new is for?
>>
>
> So something like `new(data) auto(createType())`?
>
> In any case, I think I have a better solution. Just make P0135 do what
> you're asking for.
>
> That is, add wording to P0135 that allows `new TypeName(function(...))` to
> elide the move completely. This would mean that, if `TypeName` is an exact
> match to the return value of `function(...)`, then the compiler will
> allocate the memory (or use placement syntax to get it), then pass that
> memory as the return value to `function`, which will initialize it.
>
> This way, you don't need new syntax.
>

What new syntax? That's exactly what "new auto(function(...))" would do,
except that it'd also deduce the type so you don't need to repeat it. "new
auto" has been around since C++11.

--

---
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/.

--001a1140c11ad2fad10524c680a4
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Nov 17, 2015 at 4:47 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a href=3D"m=
ailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>&gt;</s=
pan> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex">On Tuesday, November 17, 2015=
 at 7:17:58 PM UTC-5, Richard Smith wrote:<blockquote class=3D"gmail_quote"=
 style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><span class=3D"">On=
 Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a rel=3D"=
nofollow">jmck...@gmail.com</a>&gt;</span> wrote:<br></span><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><span class=3D"">On Monday, November 16, 2015 at 9:06:48 PM=
 UTC-5, Richard Smith wrote:</span><span class=3D""><div><div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"=
><div></div><div>With P0135, we can have factory functions that return nonm=
oveable types. It would be useful to be able to construct such returned obj=
ects on the heap. However, while you can&#39;t use &#39;new createType()&#3=
9;, you may be able to use &#39;new auto(createType())&#39;.</div></div></d=
iv></div></blockquote><br></div></div>And what exactly does this do? Alloca=
te memory and pass that as the return value? I&#39;d much rather have a mor=
e general syntax for something like that, so that you could use a user-prov=
ided buffer rather than only what `operator new` returns.</span></blockquot=
e><span class=3D""><div><br></div><div>That&#39;s what placement new is for=
?=C2=A0</div></span></div></div></div></blockquote><div><br>So something li=
ke `new(data) auto(createType())`?<br><br>In any case, I think I have a bet=
ter solution. Just make P0135 do what you&#39;re asking for.<br><br>That is=
, add wording to P0135 that allows `new TypeName(function(...))` to elide t=
he move completely. This would mean that, if `TypeName` is an exact match t=
o the return value of `function(...)`, then the compiler will allocate the =
memory (or use placement syntax to get it), then pass that memory as the re=
turn value to `function`, which will initialize it.<br><br>This way, you do=
n&#39;t need new syntax.</div></blockquote><div><br></div><div>What new syn=
tax? That&#39;s exactly what &quot;new auto(function(...))&quot; would do, =
except that it&#39;d also deduce the type so you don&#39;t need to repeat i=
t. &quot;new auto&quot; has been around since C++11.</div></div></div></div=
>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--001a1140c11ad2fad10524c680a4--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Tue, 17 Nov 2015 17:31:24 -0800 (PST)
Raw View
------=_Part_3842_313252348.1447810284897
Content-Type: multipart/alternative;
 boundary="----=_Part_3843_931371312.1447810284897"

------=_Part_3843_931371312.1447810284897
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 17, 2015 at 4:47:22 PM UTC-8, Nicol Bolas wrote:
>
> On Tuesday, November 17, 2015 at 7:17:58 PM UTC-5, Richard Smith wrote:
>>
>> On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>>
>>> On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:
>>>
>>>> With P0135, we can have factory functions that return nonmoveable=20
>>>> types. It would be useful to be able to construct such returned object=
s on=20
>>>> the heap. However, while you can't use 'new createType()', you may be =
able=20
>>>> to use 'new auto(createType())'.
>>>>
>>>
>>> And what exactly does this do? Allocate memory and pass that as the=20
>>> return value? I'd much rather have a more general syntax for something =
like=20
>>> that, so that you could use a user-provided buffer rather than only wha=
t=20
>>> `operator new` returns.
>>
>>
>> That's what placement new is for?=20
>>
>
> So something like `new(data) auto(createType())`?
>
> In any case, I think I have a better solution. Just make P0135 do what=20
> you're asking for.
>
> That is, add wording to P0135 that allows `new TypeName(function(...))` t=
o=20
> elide the move completely. This would mean that, if `TypeName` is an exac=
t=20
> match to the return value of `function(...)`, then the compiler will=20
> allocate the memory (or use placement syntax to get it), then pass that=
=20
> memory as the return value to `function`, which will initialize it.
>
=20
Does copy-elision work in this context today? i.e. are implementations=20
allowed to elide the copy/move construction of the "*this parameter" to the=
=20
constructor call triggered by a placement-new?  If not, that sounds like=20
something that *should* be allowed, even in the absence of Richard Smith's=
=20
P0135 <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html=
>
..

It seems to me that P0135 would make it mandatory that `new (p) T(f(...))`=
=20
wouldn't involve any moves or copies; it would simply designate (T*)p as=20
the address of the return value of f(...), and then call f(...) =E2=80=94 s=
o it=20
would work even if T were a non-moveable type.  Richard, isn't that the=20
basic idea of P0135?

(`new T` versus `new auto` seems like a red herring to me, or at least I=20
don't understand how changing `auto` to `T` could possibly affect the=20
semantics of the above code.)

=E2=80=93Arthur

--=20

---=20
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 e=
mail 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-proposa=
ls/.

------=_Part_3843_931371312.1447810284897
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 17, 2015 at 4:47:22 PM UTC-8, Nicol Bolas wrote:<block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;">On Tuesday, November 17, 2015 at 7:1=
7:58 PM UTC-5, Richard Smith wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"=
><div dir=3D"ltr"><div><div class=3D"gmail_quote">On Mon, Nov 16, 2015 at 6=
:24 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a rel=3D"nofollow">jmck...@gmail=
..com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Monday, Nov=
ember 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:<div><div><blockquo=
te class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_qu=
ote"><div></div><div>With P0135, we can have factory functions that return =
nonmoveable types. It would be useful to be able to construct such returned=
 objects on the heap. However, while you can&#39;t use &#39;new createType(=
)&#39;, you may be able to use &#39;new auto(createType())&#39;.</div></div=
></div></div></blockquote><br></div></div>And what exactly does this do? Al=
locate memory and pass that as the return value? I&#39;d much rather have a=
 more general syntax for something like that, so that you could use a user-=
provided buffer rather than only what `operator new` returns.</blockquote><=
div><br></div><div>That&#39;s what placement new is for?=C2=A0</div></div><=
/div></div></blockquote><div><br>So something like `new(data) auto(createTy=
pe())`?<br><br>In any case, I think I have a better solution. Just make P01=
35 do what you&#39;re asking for.<br><br>That is, add wording to P0135 that=
 allows `new TypeName(function(...))` to elide the move completely. This wo=
uld mean that, if `TypeName` is an exact match to the return value of `func=
tion(...)`, then the compiler will allocate the memory (or use placement sy=
ntax to get it), then pass that memory as the return value to `function`, w=
hich will initialize it.<br></div></blockquote><div>=C2=A0</div><div>Does c=
opy-elision work in this context today? i.e. are implementations allowed to=
 elide the copy/move construction of the &quot;<font face=3D"courier new, m=
onospace">*this</font> parameter&quot; to the constructor call triggered by=
 a placement-new? =C2=A0If not, that sounds like something that <i>should</=
i> be allowed, even in the absence of Richard Smith&#39;s=C2=A0<a href=3D"h=
ttp://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html">P0135<=
/a>.</div><div><br></div><div>It seems to me that P0135 would make it manda=
tory that `new (p) T(f(...))` wouldn&#39;t involve any moves or copies; it =
would simply designate (T*)p as the address of the return value of f(...), =
and then call f(...) =E2=80=94 so it would work even if T were a non-moveab=
le type. =C2=A0Richard, isn&#39;t that the basic idea of P0135?</div><div><=
br></div><div>(`new T` versus `new auto` seems like a red herring to me, or=
 at least I don&#39;t understand how changing `auto` to `T` could possibly =
affect the semantics of the above code.)</div><div><br></div><div>=E2=80=93=
Arthur</div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_3843_931371312.1447810284897--
------=_Part_3842_313252348.1447810284897--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 17 Nov 2015 19:17:32 -0800 (PST)
Raw View
------=_Part_4365_1408425899.1447816652118
Content-Type: multipart/alternative;
 boundary="----=_Part_4366_1364708763.1447816652119"

------=_Part_4366_1364708763.1447816652119
Content-Type: text/plain; charset=UTF-8

On Tuesday, November 17, 2015 at 8:24:29 PM UTC-5, Richard Smith wrote:
>
> On Tue, Nov 17, 2015 at 4:47 PM, Nicol Bolas <jmck...@gmail.com
> <javascript:>> wrote:
>
>> On Tuesday, November 17, 2015 at 7:17:58 PM UTC-5, Richard Smith wrote:
>>>
>>> On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>>>
>>>> On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:
>>>>
>>>>> With P0135, we can have factory functions that return nonmoveable
>>>>> types. It would be useful to be able to construct such returned objects on
>>>>> the heap. However, while you can't use 'new createType()', you may be able
>>>>> to use 'new auto(createType())'.
>>>>>
>>>>
>>>> And what exactly does this do? Allocate memory and pass that as the
>>>> return value? I'd much rather have a more general syntax for something like
>>>> that, so that you could use a user-provided buffer rather than only what
>>>> `operator new` returns.
>>>
>>>
>>> That's what placement new is for?
>>>
>>
>> So something like `new(data) auto(createType())`?
>>
>> In any case, I think I have a better solution. Just make P0135 do what
>> you're asking for.
>>
>> That is, add wording to P0135 that allows `new TypeName(function(...))`
>> to elide the move completely. This would mean that, if `TypeName` is an
>> exact match to the return value of `function(...)`, then the compiler will
>> allocate the memory (or use placement syntax to get it), then pass that
>> memory as the return value to `function`, which will initialize it.
>>
>> This way, you don't need new syntax.
>>
>
> What new syntax? That's exactly what "new auto(function(...))" would do,
> except that it'd also deduce the type so you don't need to repeat it. "new
> auto" has been around since C++11.
>

Really? That works?

Huh. You'd think, with all of the presentations about C++11 syntax and so
forth, it would have been mentioned somewhere.

So I guess it's just a matter of augmenting the P0135 wording to elide
through `new` expressions.

--

---
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_4366_1364708763.1447816652119
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tuesday, November 17, 2015 at 8:24:29 PM UTC-5, Richard Smith wrote:<blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=
=3D"gmail_quote">On Tue, Nov 17, 2015 at 4:47 PM, Nicol Bolas <span dir=3D"=
ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D=
"5cvg6W55BAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:=
&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return tru=
e;">jmck...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x">On Tuesday, November 17, 2015 at 7:17:58 PM UTC-5, Richard Smith wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border=
-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"=
gmail_quote"><span>On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <span dir=
=3D"ltr">&lt;<a rel=3D"nofollow">jmck...@gmail.com</a>&gt;</span> wrote:<br=
></span><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border=
-left:1px #ccc solid;padding-left:1ex"><span>On Monday, November 16, 2015 a=
t 9:06:48 PM UTC-5, Richard Smith wrote:</span><span><div><div><blockquote =
class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #=
ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote=
"><div></div><div>With P0135, we can have factory functions that return non=
moveable types. It would be useful to be able to construct such returned ob=
jects on the heap. However, while you can&#39;t use &#39;new createType()&#=
39;, you may be able to use &#39;new auto(createType())&#39;.</div></div></=
div></div></blockquote><br></div></div>And what exactly does this do? Alloc=
ate memory and pass that as the return value? I&#39;d much rather have a mo=
re general syntax for something like that, so that you could use a user-pro=
vided buffer rather than only what `operator new` returns.</span></blockquo=
te><span><div><br></div><div>That&#39;s what placement new is for?=C2=A0</d=
iv></span></div></div></div></blockquote><div><br>So something like `new(da=
ta) auto(createType())`?<br><br>In any case, I think I have a better soluti=
on. Just make P0135 do what you&#39;re asking for.<br><br>That is, add word=
ing to P0135 that allows `new TypeName(function(...))` to elide the move co=
mpletely. This would mean that, if `TypeName` is an exact match to the retu=
rn value of `function(...)`, then the compiler will allocate the memory (or=
 use placement syntax to get it), then pass that memory as the return value=
 to `function`, which will initialize it.<br><br>This way, you don&#39;t ne=
ed new syntax.</div></blockquote><div><br></div><div>What new syntax? That&=
#39;s exactly what &quot;new auto(function(...))&quot; would do, except tha=
t it&#39;d also deduce the type so you don&#39;t need to repeat it. &quot;n=
ew auto&quot; has been around since C++11.</div></div></div></div></blockqu=
ote><div><br>Really? That works?<br><br>Huh. You&#39;d think, with all of t=
he presentations about C++11 syntax and so forth, it would have been mentio=
ned somewhere.<br><br>So I guess it&#39;s just a matter of augmenting the P=
0135 wording to elide through `new` expressions.<br></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_4366_1364708763.1447816652119--
------=_Part_4365_1408425899.1447816652118--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 17 Nov 2015 19:53:59 -0800
Raw View
On Tuesday 17 November 2015 19:17:32 Nicol Bolas wrote:
> Huh. You'd think, with all of the presentations about C++11 syntax and so
> forth, it would have been mentioned somewhere.

I'd never thought about it, but new auto(x) makes sense. It's one of those
unintended side-effects that come naturally from the definition. Like
templates being Turing complete.

Anyway, the syntax
 auto x = new (data) MyType(function());

is much uglier than
 auto x = MyType();

This calls for a library class that
 a) provides sufficient storage via std::aligned_storage
 b) facilitates the construction syntax
 c) destroys the object
 d) provides operator->() and operator T*()

 auto x = holder<MyType>(ctorFunction, arg1);
 x->member_in_MyType();
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
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/.

.


Author: Jonas Persson <l.j.persson@gmail.com>
Date: Wed, 18 Nov 2015 09:12:34 +0100
Raw View
On Wed, Nov 18, 2015 at 2:24 AM, Richard Smith <richard@metafoo.co.uk> wrote:
> On Tue, Nov 17, 2015 at 4:47 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
>>
>> On Tuesday, November 17, 2015 at 7:17:58 PM UTC-5, Richard Smith wrote:
>>>
>>> On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>>>>
>>>> On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:
>>>>>
>>>>> With P0135, we can have factory functions that return nonmoveable
>>>>> types. It would be useful to be able to construct such returned objects on
>>>>> the heap. However, while you can't use 'new createType()', you may be able
>>>>> to use 'new auto(createType())'.
>>>>
>>>>
>>>> And what exactly does this do? Allocate memory and pass that as the
>>>> return value? I'd much rather have a more general syntax for something like
>>>> that, so that you could use a user-provided buffer rather than only what
>>>> `operator new` returns.
>>>
>>>
>>> That's what placement new is for?
>>
>>
>> So something like `new(data) auto(createType())`?
>>
>> In any case, I think I have a better solution. Just make P0135 do what
>> you're asking for.
>>
>> That is, add wording to P0135 that allows `new TypeName(function(...))` to
>> elide the move completely. This would mean that, if `TypeName` is an exact
>> match to the return value of `function(...)`, then the compiler will
>> allocate the memory (or use placement syntax to get it), then pass that
>> memory as the return value to `function`, which will initialize it.
>>
>> This way, you don't need new syntax.
>
>
> What new syntax? That's exactly what "new auto(function(...))" would do,
> except that it'd also deduce the type so you don't need to repeat it. "new
> auto" has been around since C++11.

Will this work with
auto x = std::make_unique<auto>(function());
cause we don't want to want to have a new use case that encourage
naked new calls in application code.

  / Jonas

--

---
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/.

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 18 Nov 2015 06:09:36 -0800 (PST)
Raw View
------=_Part_2077_745552411.1447855776780
Content-Type: multipart/alternative;
 boundary="----=_Part_2078_767364376.1447855776780"

------=_Part_2078_767364376.1447855776780
Content-Type: text/plain; charset=UTF-8

On Tuesday, November 17, 2015 at 10:54:05 PM UTC-5, Thiago Macieira wrote:
>
> On Tuesday 17 November 2015 19:17:32 Nicol Bolas wrote:
> > Huh. You'd think, with all of the presentations about C++11 syntax and
> so
> > forth, it would have been mentioned somewhere.
>
> I'd never thought about it, but new auto(x) makes sense. It's one of those
> unintended side-effects that come naturally from the definition. Like
> templates being Turing complete.
>
> Anyway, the syntax
>         auto x = new (data) MyType(function());
>
> is much uglier than
>         auto x = MyType();
>

Yes, it is more cumbersome. But it:

1) does not directly call `MyType`'s constructor.

2) allows the user to provide the `data` that defines the memory storage.

3) makes it abundantly clear that you are intended to dynamically destroy
the object.

I see no reason why using factory functions *must* look identical to
constructor syntax.

It seems to me that there are two times when you want to use a factory
function. In one case, you're dealing with an object where single-stage
construction just isn't possible. So you make all the constructors private,
and you make the factory constructors friends.

The other case is where you're applying some wrapper type to the actual
type, such as `make_shared`. After all, `make_shared<T>` does not return a
`T`; it returns a `shared_ptr<T>`.

I could see some argument for why the first case ought to look more like a
constructor. But I see no reason why wrapper factories ought to.


>
> This calls for a library class that
>  a) provides sufficient storage via std::aligned_storage
>  b) facilitates the construction syntax
>  c) destroys the object
>  d) provides operator->() and operator T*()
>
>         auto x = holder<MyType>(ctorFunction, arg1);
>         x->member_in_MyType();
>

Generally speaking, I'm not sure why someone would want that. I could
understand if `holder<T>` had different semantics from `T` (synthesizing
copy assignment from copy construction or whatever). But if it provides no
differences in behavior from `T`, why not just do `auto x =
ctorFunction(arg1);`?

--

---
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_2078_767364376.1447855776780
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, November 17, 2015 at 10:54:05 PM UTC-5, Thiago=
 Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Tuesday 17 =
November 2015 19:17:32 Nicol Bolas wrote:
<br>&gt; Huh. You&#39;d think, with all of the presentations about C++11 sy=
ntax and so=20
<br>&gt; forth, it would have been mentioned somewhere.
<br>
<br>I&#39;d never thought about it, but new auto(x) makes sense. It&#39;s o=
ne of those=20
<br>unintended side-effects that come naturally from the definition. Like=
=20
<br>templates being Turing complete.
<br>
<br>Anyway, the syntax
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0auto x =3D new (data) M=
yType(function());
<br>
<br>is much uglier than
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0auto x =3D MyType();
<br></blockquote><div><br>Yes, it is more cumbersome. But it:<br><br>1) doe=
s not directly call `MyType`&#39;s constructor.<br><br>2) allows the user t=
o provide the `data` that defines the memory storage.<br><br>3) makes it ab=
undantly clear that you are intended to dynamically destroy the object.<br>=
<br>I see no reason why using factory functions <i>must</i> look identical =
to constructor syntax.<br><br>It seems to me that there are two times when =
you want to use a factory function. In one case, you&#39;re dealing with an=
 object where single-stage construction just isn&#39;t possible. So you mak=
e all the constructors private, and you make the factory constructors frien=
ds.<br><br>The other case is where you&#39;re applying some wrapper type to=
 the actual type, such as `make_shared`. After all, `make_shared&lt;T&gt;` =
does not return a `T`; it returns a `shared_ptr&lt;T&gt;`.<br><br>I could s=
ee some argument for why the first case ought to look more like a construct=
or. But I see no reason why wrapper factories ought to.<br>=C2=A0<br></div>=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;">
<br>This calls for a library class that
<br>=C2=A0a) provides sufficient storage via std::aligned_storage
<br>=C2=A0b) facilitates the construction syntax
<br>=C2=A0c) destroys the object
<br>=C2=A0d) provides operator-&gt;() and operator T*()
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0auto x =3D holder&lt;My=
Type&gt;(ctorFunction, arg1);
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0x-&gt;member_in_MyType(=
);<br></blockquote><div><br>Generally speaking, I&#39;m not sure why someon=
e would want that. I could understand if `holder&lt;T&gt;` had different se=
mantics from `T` (synthesizing copy assignment from copy construction or wh=
atever). But if it provides no differences in behavior from `T`, why not ju=
st do `auto x =3D ctorFunction(arg1);`?<br></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_2078_767364376.1447855776780--
------=_Part_2077_745552411.1447855776780--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 18 Nov 2015 08:04:26 -0800
Raw View
On Wednesday 18 November 2015 06:09:36 Nicol Bolas wrote:
> Generally speaking, I'm not sure why someone would want that. I could
> understand if `holder<T>` had different semantics from `T` (synthesizing
> copy assignment from copy construction or whatever). But if it provides no
> differences in behavior from `T`, why not just do `auto x =
> ctorFunction(arg1);`?

I have to punt back to the OP: what's the difference between a constructor
function and a regular functionr returning the type in question?

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
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/.

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Wed, 18 Nov 2015 14:18:31 -0800
Raw View
--001a1143ec22c5fdd10524d805d1
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tue, Nov 17, 2015 at 5:31 PM, Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
wrote:

> On Tuesday, November 17, 2015 at 4:47:22 PM UTC-8, Nicol Bolas wrote:
>>
>> On Tuesday, November 17, 2015 at 7:17:58 PM UTC-5, Richard Smith wrote:
>>>
>>> On Mon, Nov 16, 2015 at 6:24 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>>>
>>>> On Monday, November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:
>>>>
>>>>> With P0135, we can have factory functions that return nonmoveable
>>>>> types. It would be useful to be able to construct such returned objec=
ts on
>>>>> the heap. However, while you can't use 'new createType()', you may be=
 able
>>>>> to use 'new auto(createType())'.
>>>>>
>>>>
>>>> And what exactly does this do? Allocate memory and pass that as the
>>>> return value? I'd much rather have a more general syntax for something=
 like
>>>> that, so that you could use a user-provided buffer rather than only wh=
at
>>>> `operator new` returns.
>>>
>>>
>>> That's what placement new is for?
>>>
>>
>> So something like `new(data) auto(createType())`?
>>
>> In any case, I think I have a better solution. Just make P0135 do what
>> you're asking for.
>>
>> That is, add wording to P0135 that allows `new TypeName(function(...))`
>> to elide the move completely. This would mean that, if `TypeName` is an
>> exact match to the return value of `function(...)`, then the compiler wi=
ll
>> allocate the memory (or use placement syntax to get it), then pass that
>> memory as the return value to `function`, which will initialize it.
>>
>
> Does copy-elision work in this context today? i.e. are implementations
> allowed to elide the copy/move construction of the "*this parameter" to
> the constructor call triggered by a placement-new?  If not, that sounds
> like something that *should* be allowed, even in the absence of Richard
> Smith's P0135
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html>.
>

Yes, it's allowed, and the copy is elided in today's implementations.

It seems to me that P0135 would make it mandatory that `new (p) T(f(...))`
> wouldn't involve any moves or copies; it would simply designate (T*)p as
> the address of the return value of f(...), and then call f(...) =E2=80=94=
 so it
> would work even if T were a non-moveable type.  Richard, isn't that the
> basic idea of P0135?
>

Essentially, yes.

(`new T` versus `new auto` seems like a red herring to me, or at least I
> don't understand how changing `auto` to `T` could possibly affect the
> semantics of the above code.)
>

I agree. I think Nicol and I were actually in violent agreement here.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--001a1143ec22c5fdd10524d805d1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Nov 17, 2015 at 5:31 PM, Arthur O&#39;Dwyer <span dir=3D"ltr">&lt;<a hr=
ef=3D"mailto:arthur.j.odwyer@gmail.com" target=3D"_blank">arthur.j.odwyer@g=
mail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span cl=
ass=3D"">On Tuesday, November 17, 2015 at 4:47:22 PM UTC-8, Nicol Bolas wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex">On Tuesday, November 17, 2015 at=
 7:17:58 PM UTC-5, Richard Smith wrote:<blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote">On Mon, Nov 16, 2015 a=
t 6:24 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a rel=3D"nofollow">jmck...@gm=
ail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Monday, =
November 16, 2015 at 9:06:48 PM UTC-5, Richard Smith wrote:<div><div><block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail=
_quote"><div></div><div>With P0135, we can have factory functions that retu=
rn nonmoveable types. It would be useful to be able to construct such retur=
ned objects on the heap. However, while you can&#39;t use &#39;new createTy=
pe()&#39;, you may be able to use &#39;new auto(createType())&#39;.</div></=
div></div></div></blockquote><br></div></div>And what exactly does this do?=
 Allocate memory and pass that as the return value? I&#39;d much rather hav=
e a more general syntax for something like that, so that you could use a us=
er-provided buffer rather than only what `operator new` returns.</blockquot=
e><div><br></div><div>That&#39;s what placement new is for?=C2=A0</div></di=
v></div></div></blockquote><div><br>So something like `new(data) auto(creat=
eType())`?<br><br>In any case, I think I have a better solution. Just make =
P0135 do what you&#39;re asking for.<br><br>That is, add wording to P0135 t=
hat allows `new TypeName(function(...))` to elide the move completely. This=
 would mean that, if `TypeName` is an exact match to the return value of `f=
unction(...)`, then the compiler will allocate the memory (or use placement=
 syntax to get it), then pass that memory as the return value to `function`=
, which will initialize it.<br></div></blockquote><div>=C2=A0</div></span><=
div>Does copy-elision work in this context today? i.e. are implementations =
allowed to elide the copy/move construction of the &quot;<font face=3D"cour=
ier new, monospace">*this</font> parameter&quot; to the constructor call tr=
iggered by a placement-new?=C2=A0 If not, that sounds like something that <=
i>should</i> be allowed, even in the absence of Richard Smith&#39;s=C2=A0<a=
 href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.ht=
ml" target=3D"_blank">P0135</a>.</div></blockquote><div><br></div><div>Yes,=
 it&#39;s allowed, and the copy is elided in today&#39;s implementations.</=
div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
..8ex;border-left:1px #ccc solid;padding-left:1ex"><div>It seems to me that =
P0135 would make it mandatory that `new (p) T(f(...))` wouldn&#39;t involve=
 any moves or copies; it would simply designate (T*)p as the address of the=
 return value of f(...), and then call f(...) =E2=80=94 so it would work ev=
en if T were a non-moveable type.=C2=A0 Richard, isn&#39;t that the basic i=
dea of P0135?</div></blockquote><div><br></div><div>Essentially, yes.</div>=
<div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div>(`new T` versus `new aut=
o` seems like a red herring to me, or at least I don&#39;t understand how c=
hanging `auto` to `T` could possibly affect the semantics of the above code=
..)</div></blockquote><div><br></div><div>I agree. I think Nicol and I were =
actually in violent agreement here.=C2=A0</div></div></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--001a1143ec22c5fdd10524d805d1--

.