220 8501 <031149b3-1c5b-4c6d-a827-82d29bc73d6f@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: A new keyword for either a type or a variable
 (typical use case for variadic template template)?
Date: Fri, 10 Jan 2014 02:01:31 -0800 (PST)
Lines: 254
Approved: news@gmane.org
Message-ID: <031149b3-1c5b-4c6d-a827-82d29bc73d6f@isocpp.org>
References: <f4ec2cca-5951-447f-a938-0b2e5e3e233f@isocpp.org>	<-5123564187529511709@gmail297201516>	<52CB7506.1000906@gmail.com>	<CAOfiQqk4rRTRFX3dbcq33z2C190ZHUGRVUhM0WRJehPZEwFJ8g@mail.gmail.com>	<62bda680-3dd7-4be8-8ac5-0d2e08bf6d99@isocpp.org>	<CAOfiQq=fvi-mzf6mP4B2XBgCeHfimX857Jff+Nz=iUeHW5W1nw@mail.gmail.com>	<52CDFB2D.4050703@gmail.com>	<-9126987679220332623@gmail297201516>	<52CE0F54.5020800@gmail.com>	<CAOfiQqmi3UHRSvgQB_5ZdWrM3oRog4RpgsighU2a3p6HjoVq8g@mail.gmail.com>	<52CF3AB0.7090102@gmail.com>	<52CF3D80.9090702@gmail.com> <CAOfiQqkfdkKXTOX9J2kn9GB4KCzf3UbkGXcvqe+89ZEbB7X4Gw@mail.gmail.com>
 <52CF4DC0.20100@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_148_30962611.1389348092038"
X-Trace: ger.gmane.org 1389348089 8426 80.91.229.3 (10 Jan 2014 10:01:29 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 10 Jan 2014 10:01:29 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRIRSPDTQIRB7MJX6LAKGQEKNEHN4I@isocpp.org Fri Jan 10 11:01:37 2014
Return-path: <std-proposals+bncBCRIRSPDTQIRB7MJX6LAKGQEKNEHN4I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f197.google.com ([209.85.216.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCRIRSPDTQIRB7MJX6LAKGQEKNEHN4I@isocpp.org>)
	id 1W1YuE-0008Tq-Dr
	for gclcip-std-proposals@m.gmane.org; Fri, 10 Jan 2014 11:01:34 +0100
Original-Received: by mail-qc0-f197.google.com with SMTP id r5sf6789575qcx.4
        for <gclcip-std-proposals@m.gmane.org>; Fri, 10 Jan 2014 02:01:33 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=P3Rv/Toyw6krw5vSVRrtZjAGxqQoP0TKqE0mEQQPOqg=;
        b=HMGRSFR9aWMXFn0MvPqLn6YGGksLORQUowDs+15zcYUrYhRvFPRBCK/TnRPpoaqvMi
         /pSftQNT8NdDhmlT4j7C+kzbSCK3B2KBvfhVbXK6P7GBgAK301tFBK0fbIdvv2avV14/
         2xtYtSIuuTCtF67sYnleByfNxosDItyY20no27ZDPi3OOXVoGskm41/eURFQyCvbwZtX
         MfFVneZt0bdc7B/NH1QH3NlF00b2iHcbVNloYbzoG4tROzjI2X34px+Su6LZMNpInJ8x
         nZj4dep+w/ZoNJ4pXmFKb+2phNwL/IHCEleA6I3OQg/E08IF7HX0yH2uNxcho1fwBToS
         g1yA==
X-Gm-Message-State: ALoCoQkikzuYc4BBDfLuhP6ng5ROGLIeruY6Ktg4YzaqAEy41tbuJrBdhjdIUttkHi3VhR7FxwpC
X-Received: by 10.58.100.99 with SMTP id ex3mr3217278veb.1.1389348093468;
        Fri, 10 Jan 2014 02:01:33 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.24.174 with SMTP id v14ls1343635qef.74.gmail; Fri, 10 Jan
 2014 02:01:32 -0800 (PST)
X-Received: by 10.49.85.2 with SMTP id d2mr30655qez.9.1389348092856;
        Fri, 10 Jan 2014 02:01:32 -0800 (PST)
In-Reply-To: <52CF4DC0.20100@gmail.com>
X-Original-Sender: bengt.gustafsson@beamways.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8501
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8501>

------=_Part_148_30962611.1389348092038
Content-Type: text/plain; charset=ISO-8859-1

Except that it is error prone I like your idea:

   template< ... > struct is_type : std::false_type {}; // primary 
   template<typename T> struct is_type<T> : std::true_type {}; // partial 
specialization 

(error prone in the sense that if you call it with more than one type it 
tells you it isn't a type).

But in our use case we would first have to split the incoming generic pack 
into its individual elements to be able to test them for type/non-type. Can 
this be done with only the ... feature. I think it can, but only given the 
other "auto" feature. I exemplify by a simple function to get info about 
the first element of a generic pack:

   template<...> struct HeadInfo;
   template<typename T, ...> struct HeadInfo<T, ...> {
       static const bool is_type = true;
       typedef T type;
   };
   template<auto V, ...> struct HeadInfo<V, ...> {
       static const bool is_type = false;
       typedef decltype(V) type;
       static const auto value = V;
   };

Well, now that I wrote the code I noticed that the same "default based" 
technique used for is_type is usable here too, except of course that you 
would not get the type and value members for the non typename case. Also, 
it seems that it gets hard to work with the "always variadic" nature of the 
resulting templates, for instance we could not write static const bool 
is_type = std::is_type<...> here as it would be exposed to the 
error-proneness I described at the top of this post.

My conclusion for now is that if we have 'auto' as I used it above we only 
need the ... notation for variadic generic parameters, as auto and typename 
can be used to differentiate the members of the generic pack as shown in 
the HeadInfo example. Thus a new implementation of is_type is like this:

 template< ... > struct is_type; // primary, not implemented. This prevents 
using is_type with more than one element packs.
 template<auto V> : struct is_type<V> : std::false_type {};
 template<typename T> struct is_type<T> : std::true_type {}; // partial 
specialization 

The only problem I see with this is that it is kind of weird to define the 
primary template with ... which denotes any number of anything. At least 
error messages when you instantiate with more than one parameter will be 
misleading, as it will complain about the class being incomplete rather 
than the template parameters being too many. This argument alone seems 
however to be too weak to motivate a ? feature.




Den fredagen den 10:e januari 2014 kl. 02:32:48 UTC+1 skrev David Krauss:
>
> On 1/10/14 9:07 AM, Richard Smith wrote: 
> > On Thu, Jan 9, 2014 at 4:23 PM, David Krauss <pot...@gmail.com<javascript:>> 
> wrote: 
> > 
> >> On 1/10/14 8:11 AM, David Krauss wrote: 
> >> 
> >> Given "?", you can peel off a fully-generic argument from a pack, and 
> >> pass it to another template. But the other template must be either 
> >> fully-generic, or overloaded/partially specialized. So you might as 
> >> well peel the pack in the target overloaded/partially specialized 
> >> template. All "?" buys you is the freedom to add a dispatcher between 
> >> components which are actually necessary. 
> > It allows more code reuse, by allowing handling of individual elements 
> of 
> > such a pack to be factored out. That is a valuable property, even if it 
> > only helps those people who are writing template metaprograms. 
>
> I'm still skeptical that real factoring is ever possible, i.e. that a 
> template with a fully generic non-pack parameter, and doing more than 
> forward it (which could be done by a tuple-like, pack-based utility), 
> can ever usefully be more than a simple dispatcher. This refers to the 
> primary template, not the specializations. Your previous example use 
> case did not actually use the fully-generic single argument at all, and 
> might as well have taken a pack: 
>
>    template< ... > struct is_type : std::false_type {}; // primary 
>    template<typename T> struct is_type<T> : std::true_type {}; // partial 
> specialization 
>
>
> This is assuming, as the previous example already did, that "typename" 
> is more specialized than fully-generic. Presumably "<typename>" is still 
> never more specialized than "<typename ...>". We can remove that 
> assumption, and contain the pattern making it scalable by adding that 
> tuple-like utility: 
>
>    template< ... > struct generic_tuple; // library utility 
>
>    template< typename > struct is_type : std::false_type {}; // primary 
>    template<typename T> struct is_type< generic_tuple< T > > : 
> std::true_type {}; // partial specialization 
>
>
> The user would have no need for an is_type facility, though, because 
> peeling a tuple element would always require type/value resolution. 
>
> Prototyping and practice will tell. But, let's keep an eye out for 
> unnecessary complexity masquerading as factoring. 
>
>

-- 

--- 
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_148_30962611.1389348092038
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Except that it is error prone I like your idea:<div><br></=
div><div>&nbsp; &nbsp;template&lt; ... &gt; struct is_type : std::false_typ=
e {}; // primary&nbsp;<br>&nbsp; &nbsp;template&lt;typename T&gt; struct is=
_type&lt;T&gt; : std::true_type {}; // partial specialization&nbsp;<br><br>=
(error prone in the sense that if you call it with more than one type it te=
lls you it isn't a type).</div><div><br></div><div>But in our use case we w=
ould first have to split the incoming generic pack into its individual elem=
ents to be able to test them for type/non-type. Can this be done with only =
the ... feature. I think it can, but only given the other "auto" feature. I=
 exemplify by a simple function to get info about the first element of a ge=
neric pack:</div><div><br></div><div>&nbsp; &nbsp;template&lt;...&gt; struc=
t HeadInfo;</div><div>&nbsp; &nbsp;template&lt;typename T, ...&gt; struct H=
eadInfo&lt;T, ...&gt; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp;static const b=
ool is_type =3D true;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;typedef T type;<=
/div><div>&nbsp; &nbsp;};</div><div>&nbsp; &nbsp;template&lt;auto V, ...&gt=
; struct HeadInfo&lt;V, ...&gt; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp;stat=
ic const bool is_type =3D false;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;typed=
ef decltype(V) type;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;static const auto=
 value =3D V;</div><div>&nbsp; &nbsp;};</div><div><br></div><div>Well, now =
that I wrote the code I noticed that the same "default based" technique use=
d for is_type is usable here too, except of course that you would not get t=
he type and value members for the non typename case. Also, it seems that it=
 gets hard to work with the "always variadic" nature of the resulting templ=
ates, for instance we could not write static const bool is_type =3D std::is=
_type&lt;...&gt; here as it would be exposed to the error-proneness I descr=
ibed at the top of this post.</div><div><br></div><div>My conclusion for no=
w is that if we have 'auto' as I used it above we only need the ... notatio=
n for variadic generic parameters, as auto and typename can be used to diff=
erentiate the members of the generic pack as shown in the HeadInfo example.=
 Thus a new implementation of is_type is like this:</div><div><br></div><di=
v>&nbsp;template&lt; ... &gt; struct is_type;&nbsp;// primary, not implemen=
ted. This prevents using is_type with more than one element packs.</div><di=
v>&nbsp;template&lt;auto V&gt; : struct is_type&lt;V&gt; : std::false_type =
{};<br>&nbsp;template&lt;typename T&gt; struct is_type&lt;T&gt; : std::true=
_type {}; // partial specialization&nbsp;<br></div><div><br></div><div>The =
only problem I see with this is that it is kind of weird to define the prim=
ary template with ... which denotes any number of anything. At least error =
messages when you instantiate with more than one parameter will be misleadi=
ng, as it will complain about the class being incomplete rather than the te=
mplate parameters being too many. This argument alone seems however to be t=
oo weak to motivate a ? feature.</div><div><br></div><div><br></div><div><b=
r></div><div><br>Den fredagen den 10:e januari 2014 kl. 02:32:48 UTC+1 skre=
v David Krauss:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 1/10/14 9:07=
 AM, Richard Smith wrote:
<br>&gt; On Thu, Jan 9, 2014 at 4:23 PM, David Krauss &lt;<a href=3D"javasc=
ript:" target=3D"_blank" gdf-obfuscated-mailto=3D"0fqkxdVnXzcJ" onmousedown=
=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascr=
ipt:';return true;">pot...@gmail.com</a>&gt; wrote:
<br>&gt;
<br>&gt;&gt; On 1/10/14 8:11 AM, David Krauss wrote:
<br>&gt;&gt;
<br>&gt;&gt; Given "?", you can peel off a fully-generic argument from a pa=
ck, and=20
<br>&gt;&gt; pass it to another template. But the other template must be ei=
ther=20
<br>&gt;&gt; fully-generic, or overloaded/partially specialized. So you mig=
ht as=20
<br>&gt;&gt; well peel the pack in the target overloaded/partially speciali=
zed=20
<br>&gt;&gt; template. All "?" buys you is the freedom to add a dispatcher =
between=20
<br>&gt;&gt; components which are actually necessary.=20
<br>&gt; It allows more code reuse, by allowing handling of individual elem=
ents of
<br>&gt; such a pack to be factored out. That is a valuable property, even =
if it
<br>&gt; only helps those people who are writing template metaprograms.
<br>
<br>I'm still skeptical that real factoring is ever possible, i.e. that a=
=20
<br>template with a fully generic non-pack parameter, and doing more than=
=20
<br>forward it (which could be done by a tuple-like, pack-based utility),=
=20
<br>can ever usefully be more than a simple dispatcher. This refers to the=
=20
<br>primary template, not the specializations. Your previous example use=20
<br>case did not actually use the fully-generic single argument at all, and=
=20
<br>might as well have taken a pack:
<br>
<br>&nbsp; &nbsp;template&lt; ... &gt; struct is_type : std::false_type {};=
 // primary
<br>&nbsp; &nbsp;template&lt;typename T&gt; struct is_type&lt;T&gt; : std::=
true_type {}; // partial specialization
<br>
<br>
<br>This is assuming, as the previous example already did, that "typename"=
=20
<br>is more specialized than fully-generic. Presumably "&lt;typename&gt;" i=
s still=20
<br>never more specialized than "&lt;typename ...&gt;". We can remove that=
=20
<br>assumption, and contain the pattern making it scalable by adding that=
=20
<br>tuple-like utility:
<br>
<br>&nbsp; &nbsp;template&lt; ... &gt; struct generic_tuple; // library uti=
lity
<br>
<br>&nbsp; &nbsp;template&lt; typename &gt; struct is_type : std::false_typ=
e {}; // primary
<br>&nbsp; &nbsp;template&lt;typename T&gt; struct is_type&lt; generic_tupl=
e&lt; T &gt; &gt; : std::true_type {}; // partial specialization
<br>
<br>
<br>The user would have no need for an is_type facility, though, because=20
<br>peeling a tuple element would always require type/value resolution.
<br>
<br>Prototyping and practice will tell. But, let's keep an eye out for=20
<br>unnecessary complexity masquerading as factoring.
<br>
<br></blockquote></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_148_30962611.1389348092038--

.
