220 18733 <C9C172D2-327C-47E6-B019-94D2FA0F3BF1@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Factory functions as deducing constructors? (N4471)
Date: Wed, 24 Jun 2015 17:44:52 +0800
Lines: 124
Approved: news@gmane.org
Message-ID: <C9C172D2-327C-47E6-B019-94D2FA0F3BF1@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_44A6BC3A-C329-4E6E-B722-B3EC9B0E10E1"
X-Trace: ger.gmane.org 1435139113 29399 80.91.229.3 (24 Jun 2015 09:45:13 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 24 Jun 2015 09:45:13 +0000 (UTC)
Cc: Richard Smith <richard@metafoo.co.uk>
To: Mike Spertus <mike_spertus@symantec.com>,
 std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBIHYVGWAKGQERHCA32Y@isocpp.org Wed Jun 24 11:45:09 2015
Return-path: <std-proposals+bncBCW25A7E3QCRBIHYVGWAKGQERHCA32Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yk0-f200.google.com ([209.85.160.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBIHYVGWAKGQERHCA32Y@isocpp.org>)
	id 1Z7hEw-0006XY-Dh
	for gclcip-std-proposals@m.gmane.org; Wed, 24 Jun 2015 11:45:07 +0200
Original-Received: by ykay124 with SMTP id y124sf32207494yka.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 24 Jun 2015 02:45:05 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:content-type:subject:date:message-id:cc:to
         :mime-version:x-original-sender:x-original-authentication-results
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=AmgKPxnePbHD3xIwVRkqJ7zks8WQs04rgfeZdampMTA=;
        b=X+cTokonqoLvqU7vW6CL/hhvhVUDljbWLLgG5js3SMTBPI4qtV21x/T4rJLTPzI3Md
         rHL1rFasezzD4vb/c1YIiUvdGheoXMQMjRJ2vJTo1ptgLQ1XT72EscEeDr4IX8eSMkqE
         wtRxZ2G7nzFyn+N+Th1PKEO6vJEOU3VErk3kNaMnnMM7V5GZA5RS2RdqIRAYRwMv7kag
         7bfbMmjYckG5u0bGK3PDaO4SMfzz10m8ksPSM/fwdYAYCMKzgqD+WenXetNiTMCDMrmj
         OLMxCAgAXB9Uf2crz+2FsU2VEFMQZ0gPKQyJ+U08nWfBLaKimsE0rbUoa6IqSSArSkx1
         Y82Q==
X-Gm-Message-State: ALoCoQlH3BMQXhs8gx+vfGHwFDCsTV9fxi5CBBw1d0JNyf9jaPGUe6knnl6fnNQQYmzBduMiMENB
X-Received: by 10.13.241.68 with SMTP id a65mr10514829ywf.50.1435139105437;
        Wed, 24 Jun 2015 02:45:05 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.114.73 with SMTP id je9ls477441igb.38.gmail; Wed, 24 Jun
 2015 02:45:04 -0700 (PDT)
X-Received: by 10.66.66.46 with SMTP id c14mr79046755pat.71.1435139104539;
        Wed, 24 Jun 2015 02:45:04 -0700 (PDT)
Original-Received: from mail-pa0-x22e.google.com (mail-pa0-x22e.google.com. [2607:f8b0:400e:c03::22e])
        by mx.google.com with ESMTPS id so4si39045631pbc.76.2015.06.24.02.45.04
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 24 Jun 2015 02:45:04 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c03::22e as permitted sender) client-ip=2607:f8b0:400e:c03::22e;
Original-Received: by padev16 with SMTP id ev16so25963136pad.0
        for <std-proposals@isocpp.org>; Wed, 24 Jun 2015 02:45:04 -0700 (PDT)
X-Received: by 10.70.48.68 with SMTP id j4mr67889205pdn.111.1435139104440;
        Wed, 24 Jun 2015 02:45:04 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.44.94])
        by mx.google.com with ESMTPSA id im7sm26058215pbc.25.2015.06.24.02.44.59
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 24 Jun 2015 02:45:03 -0700 (PDT)
X-Mailer: Apple Mail (2.2098)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c03::22e as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:18733
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/18733>

--Apple-Mail=_44A6BC3A-C329-4E6E-B722-B3EC9B0E10E1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

Hi Mike,

Most libraries already implement factory function templates, e.g. make_thin=
g(). Why not just let them be named e.g. thing(), aliasing the class templa=
te?

No new deduction rules are needed.
It=E2=80=99s a non-breaking change because such aliasing is currently disal=
lowed.
It differs from established practice only by renaming.
The full flexibility of factory functions is preserved, including explicit =
template arguments.
It does not intrude into the class template implementation.

For the sake of member templates, such a function template (or function) sh=
ould still be found by a qualified-id preceded by the typename keyword. It =
should also be illegal to take its address, or to do anything with its name=
 or template-id besides call it. The factory should defer to real construct=
ors when the explicit template argument list satisfies the class template p=
arameters.

Require the factory to be declared after the initial declaration of the cla=
ss template, and require its return type to be a specialization.

Implementation model: Attach the overload set of factory functions to the c=
lass template. When name lookup finds the class template, grab the factorie=
s too. If template arguments are provided, treat the class template as an o=
verload to the factories and run template argument deduction for explicit a=
rguments ([temp.deduct]/1-5). If the class template has not suffered a dedu=
ction failure, terminate deduction and restart overload resolution using it=
s constructors.

I=E2=80=99d also like to propose enforced copy elision, such that simple fa=
ctory functions don=E2=80=99t require move construction. (Call it =E2=80=9C=
perfect return.=E2=80=9D) This seems like a separate feature. However, it w=
ould be nice to have both.

Long ago, in some early C++ implementations at least, constructors were non=
-member factory functions. Hopefully this won=E2=80=99t be seen as =E2=80=
=9Ccoming full circle.=E2=80=9D It=E2=80=99s really not, since the factory =
has no special abilities or status besides sharing a name.

	- D

--=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/.

--Apple-Mail=_44A6BC3A-C329-4E6E-B722-B3EC9B0E10E1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><div class=3D"">Hi=
 Mike,</div><div class=3D""><br class=3D""></div><div class=3D"">Most libra=
ries already implement factory function templates, e.g. <font face=3D"Couri=
er" class=3D"">make_thing()</font>. Why not just let them be named e.g.&nbs=
p;<font face=3D"Courier" class=3D"">thing()</font>, aliasing the class temp=
late?</div><div class=3D""><br class=3D""></div><div class=3D""><ul class=
=3D""><li class=3D"">No new deduction rules are needed.</li><li class=3D"">=
It=E2=80=99s a non-breaking change because such aliasing is currently disal=
lowed.</li><li class=3D"">It differs from established practice only by rena=
ming.</li><li class=3D"">The full flexibility of factory functions is prese=
rved, including explicit template arguments.</li><li class=3D"">It does not=
 intrude into the class template implementation.</li></ul></div><div class=
=3D""><br class=3D""></div><div class=3D"">For the sake of member templates=
, such a function template (or function) should still be found by a qualifi=
ed-id preceded by the <font face=3D"Courier" class=3D"">typename</font> key=
word. It should also be illegal to take its address, or to do anything with=
 its name or template-id besides call it. The factory should defer to real =
constructors when the explicit template argument list satisfies the class t=
emplate parameters.</div><div class=3D""><br class=3D""></div><div class=3D=
"">Require the factory to be declared after the initial declaration of the =
class template, and require its return type to be a specialization.</div><d=
iv class=3D""><br class=3D""></div><div class=3D"">Implementation model: At=
tach the overload set of factory functions to the class template. When name=
 lookup finds the class template, grab the factories too. If template argum=
ents are provided, treat the class template as an overload to the factories=
 and run template argument deduction for explicit arguments ([temp.deduct]/=
1-5). If the class template has not suffered a deduction failure, terminate=
 deduction and restart overload resolution using its constructors.</div><di=
v class=3D""><br class=3D""></div><div class=3D"">I=E2=80=99d also like to =
propose enforced copy elision, such that simple factory functions don=E2=80=
=99t require move construction. (Call it =E2=80=9Cperfect return.=E2=80=9D)=
 This seems like a separate feature. However, it would be nice to have both=
..</div><div class=3D""><br class=3D""></div><div class=3D"">Long ago, in so=
me early C++ implementations at least, constructors&nbsp;<i class=3D"">were=
</i>&nbsp;non-member factory functions. Hopefully this won=E2=80=99t be see=
n as =E2=80=9Ccoming full circle.=E2=80=9D It=E2=80=99s really not, since t=
he factory has no special abilities or status besides sharing a name.</div>=
<div class=3D""><br class=3D""></div><div class=3D""><span class=3D"Apple-t=
ab-span" style=3D"white-space:pre">	</span>- D</div><div class=3D""><br cla=
ss=3D""></div></body></html>

<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 />

--Apple-Mail=_44A6BC3A-C329-4E6E-B722-B3EC9B0E10E1--

.
