220 8514 <5f8d31ad-a264-4389-976d-840a71d07f2e@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 15:41:39 -0800 (PST)
Lines: 244
Approved: news@gmane.org
Message-ID: <5f8d31ad-a264-4389-976d-840a71d07f2e@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>
 <031149b3-1c5b-4c6d-a827-82d29bc73d6f@isocpp.org>
 <628bba42-9a56-42d7-8182-0de7c10c437b@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_613_1796018.1389397299857"
X-Trace: ger.gmane.org 1389397295 7432 80.91.229.3 (10 Jan 2014 23:41:35 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 10 Jan 2014 23:41:35 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRIRSPDTQIRBNEKYKLAKGQEG4H4DSY@isocpp.org Sat Jan 11 00:41:43 2014
Return-path: <std-proposals+bncBCRIRSPDTQIRBNEKYKLAKGQEG4H4DSY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f197.google.com ([209.85.223.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCRIRSPDTQIRBNEKYKLAKGQEG4H4DSY@isocpp.org>)
	id 1W1lht-0000QS-VK
	for gclcip-std-proposals@m.gmane.org; Sat, 11 Jan 2014 00:41:42 +0100
Original-Received: by mail-ie0-f197.google.com with SMTP id e14sf19658374iej.8
        for <gclcip-std-proposals@m.gmane.org>; Fri, 10 Jan 2014 15:41:41 -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=gM0h3fKycTLpChHLuAP39H6I//mDRKsV62rd8OdIpto=;
        b=KJRVu1g9xIenosabpoqxjy4Fn4k52Alo7zgq1ssqwW1a69JYwV36HVy4WWvwWr/pl6
         Tzev+L5lj0GQbzHUXwZpv+QjvGwZzyGyvsQbzUUCxoK/jWVDq7yrwWUqN67eXxqOzUj/
         24zPpeUaGFYGEsgJ1v5I5pKvjc+wWIdTEPzOuVH65+jiQuQM2Nfiz5osbUBFT1s3a/lW
         ujIZfQnASHjCsq5yjT3Nc7XzSBu1GEWydcGSdEZbf3EBV8pTFCHKVrDp9n6E/k1O8gG6
         KnM9s634rm3p76E3u7BSy1j+FoPAcYgM/8c3XjoYyR1b+hwadJZWBDoNRhvg+SMSX9TU
         C+5g==
X-Gm-Message-State: ALoCoQlyT0pcl+GXCDDmLHmmdOAvNOJHZkTqWpTpZJ579yEfo1hWLuS4U9X6DO6IOXI5hxPDe1BC
X-Received: by 10.182.66.137 with SMTP id f9mr4701186obt.3.1389397301060;
        Fri, 10 Jan 2014 15:41:41 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.24.145 with SMTP id u17ls1822277qef.42.gmail; Fri, 10 Jan
 2014 15:41:40 -0800 (PST)
X-Received: by 10.49.94.144 with SMTP id dc16mr96374qeb.21.1389397300331;
        Fri, 10 Jan 2014 15:41:40 -0800 (PST)
In-Reply-To: <628bba42-9a56-42d7-8182-0de7c10c437b@isocpp.org>
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:8514
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8514>

------=_Part_613_1796018.1389397299857
Content-Type: text/plain; charset=ISO-8859-1

Yes, you are absolutely right, the "Tail" should have been there in my 
example just as you wrote it.

So it seems right now that we can make do with the ... "generic pack" type 
and auto, but it bugs me a bit that we now have all of these forms of a 
template parameter type (where int is of course just an example):

int                  One template parameter of type int
int...               Any number of int template parameters
auto               One non-type template parameter of any type
auto...            Any number of non-type template parameters of mixed 
types*
typename       One type template parameter
typename...    Any number of type template parameters
....                  Any number of type or non-type template parameters

But not:
?                   One type or auto tempalte parameter  (apart from the 
bikeshed issue of ?)


At least from an educational standpoint it could be wise to be more 
orthogonal, which would also mean to reintroduce ?... instead of just ...

Another risk I see with using ... is that people will start to over-use it 
because it looks nice, i.e. writing template<...> for a variadic template 
template parameter even when the code only handles that the actuals are 
types.

In the back of my head I also feel that sooner of later we will find 
something that can't be done due to the omission of the lonely ? feature.

Entering the bikeshed I toyed with the use of . instead of ? It kind of 
goes nicely with ... as it would be interpreted as "many dots". The main 
problem could be that it is almost invisible on the screen especially as a 
typical usage would be template<. H,... T>. The * suggested in this thread 
is a bit scary as you can also write for instance template<int*...> which 
as another traditional meaning...  I also scanned the keyword list but 
didn't find any real candidates.

BTW: I can't seem to find any wording in the standard document (C++14) that 
allows for instance a function taking any number of ints, although I have 
seen uses of it in this list (and which I assumed was available in my list 
above):

template<int... dims> class Matrix; 

VS2012 also does not allow this. What is the status? 

* The reason for assuming that auto... would refer to any number of 
parameters of different types is that otherwise reursive decomposition like 
this would be strange:

template<auto H, auto... Ts> class Foo;

as now H is "another auto" than Ts which can bind to another type, while 
the Ts must still be the same, untill next recursion step.

Is there a paper or thread for auto template parameters?


Den fredagen den 10:e januari 2014 kl. 16:35:15 UTC+1 skrev Alex B:
>
> On Friday, January 10, 2014 5:01:31 AM UTC-5, Bengt Gustafsson wrote:
>
>>  
>>    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;
>>    };
>>  
>>
>  
> That syntax without ? would still require being able to name the generic 
> pack. Your example should be:
>  
>
> template<typename T, ...*Tail*> struct HeadInfo<T, *Tail*...> {
> static const bool is_type = true;
> typedef T type;
> };
>
>  
>  
> Giving a name would be required to disambiguate cases where there is more 
> than one generic pack:
>  
>
> template <...> struct A {};
>  
> template <class T, class U>
> struct B;
>  
> template <...ElemsT, ...ElemsU>
> struct B<A<ElemsT...>, A<ElemsU...>>
> {
> };
>
>  
> As for actual use cases (with or without ?), there is more 
> than metaprogramming refactoring sugar. I can see at least one case that it 
> would allow to fix which is boost recursive variants:
>
> *http://www.boost.org/doc/libs/1_55_0/doc/html/boost/make_recursive_variant.html*<http://www.boost.org/doc/libs/1_55_0/doc/html/boost/make_recursive_variant.html>
> Unless I'm wrong, recursive variants currently cannot contain a template 
> type with non-type parameters, which is a bit annoying. This feature would 
> make it possible.
>

-- 

--- 
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_613_1796018.1389397299857
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Yes, you are absolutely right, the "Tail" should have been=
 there in my example just as you wrote it.<div><br></div><div>So it seems r=
ight now that we can make do with the ... "generic pack" type and auto, but=
 it bugs me a bit that we now have all of these forms of a template paramet=
er type (where int is of course just an example):</div><div><br></div><div>=
int &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;One templ=
ate parameter of type int</div><div>int... &nbsp; &nbsp; &nbsp; &nbsp; &nbs=
p; &nbsp; &nbsp; Any number of int template parameters</div><div>auto &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; One non-type template parameter=
 of any type</div><div>auto... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Any=
 number of non-type template parameters of mixed types*</div><div>typename =
&nbsp; &nbsp; &nbsp; One type template parameter</div><div>typename... &nbs=
p; &nbsp;Any number of type template parameters</div><div>... &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Any number of type or non-=
type template parameters</div><div><br></div><div>But not:</div><div>? &nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; One type or auto=
 tempalte parameter &nbsp;(apart from the bikeshed issue of ?)</div><div><b=
r></div><div><br></div><div>At least from an educational standpoint it coul=
d be wise to be more orthogonal, which would also mean to reintroduce ?... =
instead of just ...</div><div><br></div><div>Another risk I see with using =
.... is that people will start to over-use it because it looks nice, i.e. wr=
iting template&lt;...&gt; for a variadic template template parameter even w=
hen the code only handles that the actuals are types.</div><div><br></div><=
div>In the back of my head I also feel that sooner of later we will find so=
mething that can't be done due to the omission of the lonely ? feature.</di=
v><div><br></div><div>Entering the bikeshed I toyed with the use of . inste=
ad of ? It kind of goes nicely with ... as it would be interpreted as "many=
 dots". The main problem could be that it is almost invisible on the screen=
 especially as a typical usage would be template&lt;. H,... T&gt;. The * su=
ggested in this thread is a bit scary as you can also write for instance te=
mplate&lt;int*...&gt; which as another traditional meaning... &nbsp;I also =
scanned the keyword list but didn't find any real candidates.</div><div><br=
></div><div>BTW: I can't seem to find any wording in the standard document =
(C++14) that allows for instance a function taking any number of ints, alth=
ough I have seen uses of it in this list (and which I assumed was available=
 in my list above):</div><div><br></div><div>template&lt;int... dims&gt; cl=
ass Matrix;&nbsp;</div><div><br></div><div>VS2012 also does not allow this.=
 What is the status?&nbsp;</div><div><br></div><div>* The reason for assumi=
ng that auto... would refer to any number of parameters of different types =
is that otherwise reursive decomposition like this would be strange:</div><=
div><br></div><div>template&lt;auto H, auto... Ts&gt; class Foo;</div><div>=
<br></div><div>as now H is "another auto" than Ts which can bind to another=
 type, while the Ts must still be the same, untill next recursion step.</di=
v><div><br></div><div>Is there a paper or thread for auto template paramete=
rs?</div><div><br></div><div><br></div><div>Den fredagen den 10:e januari 2=
014 kl. 16:35:15 UTC+1 skrev Alex B:<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>On Friday, January 10, 2014 5:01:31 AM UTC-5, B=
engt Gustafsson wrote:</div><blockquote style=3D"margin:0px 0px 0px 0.8ex;p=
adding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;bo=
rder-left-style:solid" class=3D"gmail_quote"><div dir=3D"ltr"><div>&nbsp;</=
div><div>&nbsp; &nbsp;template&lt;...&gt; struct HeadInfo;</div><div>&nbsp;=
 &nbsp;template&lt;typename T, ...&gt; struct HeadInfo&lt;T, ...&gt; {</div=
><div>&nbsp; &nbsp; &nbsp; &nbsp;static const bool is_type =3D true;</div><=
div>&nbsp; &nbsp; &nbsp; &nbsp;typedef T type;</div><div>&nbsp; &nbsp;};</d=
iv><div>&nbsp; &nbsp;template&lt;auto V, ...&gt; struct HeadInfo&lt;V, ...&=
gt; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp;static const bool is_type =3D fa=
lse;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;typedef decltype(V) type;</div><d=
iv>&nbsp; &nbsp; &nbsp; &nbsp;static const auto value =3D V;</div><div>&nbs=
p; &nbsp;};</div><div>&nbsp;</div></div></blockquote><div>&nbsp;</div><div>=
That syntax without ? would still require being able to name the generic pa=
ck. Your example should be:</div><div>&nbsp;</div><blockquote style=3D"marg=
in-right:0px" dir=3D"ltr"><div><font face=3D"courier new,monospace">templat=
e&lt;typename T, ...<strong><font color=3D"#ff0000">Tail</font></strong>&gt=
; struct HeadInfo&lt;T, <strong><font color=3D"#ff0000">Tail</font></strong=
>...&gt; {</font></div><div><font face=3D"courier new,monospace">       sta=
tic const bool is_type =3D true;</font></div><div><font face=3D"courier new=
,monospace">       typedef T type;</font></div><div><font face=3D"courier n=
ew,monospace">   };</font></div></blockquote><div>&nbsp;</div><div>&nbsp;</=
div><div>Giving a name would be required to disambiguate cases where there =
is more than one generic pack:</div><div>&nbsp;</div><blockquote style=3D"m=
argin-right:0px" dir=3D"ltr"><div><font face=3D"courier new,monospace">temp=
late &lt;...&gt; struct A {};</font></div><div><font face=3D"courier new,mo=
nospace"></font>&nbsp;</div><div><font face=3D"courier new,monospace">templ=
ate &lt;class T, class U&gt;</font></div><div><font face=3D"courier new,mon=
ospace">struct B;</font></div><div><font face=3D"courier new,monospace"></f=
ont>&nbsp;</div><div><font face=3D"courier new,monospace">template &lt;...E=
lemsT, ...ElemsU&gt;</font></div><div><font face=3D"courier new,monospace">=
struct B&lt;A&lt;ElemsT...&gt;, A&lt;ElemsU...&gt;&gt;</font></div><div><fo=
nt face=3D"courier new,monospace">{</font></div><div><font face=3D"courier =
new,monospace">};</font></div></blockquote><div>&nbsp;</div><div>As for act=
ual use cases (with or without ?),&nbsp;there is more than&nbsp;metaprogram=
ming refactoring sugar.&nbsp;I can see at least one case&nbsp;that it would=
 allow to fix which is boost recursive variants:</div><div><a href=3D"http:=
//www.boost.org/doc/libs/1_55_0/doc/html/boost/make_recursive_variant.html"=
 target=3D"_blank" onmousedown=3D"this.href=3D'http://www.google.com/url?q\=
75http%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2F1_55_0%2Fdoc%2Fhtml%2Fboost%2Fm=
ake_recursive_variant.html\46sa\75D\46sntz\0751\46usg\75AFQjCNEkLx7NjbgeN_C=
2OWEwhZAKDITriQ';return true;" onclick=3D"this.href=3D'http://www.google.co=
m/url?q\75http%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2F1_55_0%2Fdoc%2Fhtml%2Fb=
oost%2Fmake_recursive_variant.html\46sa\75D\46sntz\0751\46usg\75AFQjCNEkLx7=
NjbgeN_C2OWEwhZAKDITriQ';return true;"><u><font color=3D"#0066cc">http://ww=
w.boost.org/doc/libs/<wbr>1_55_0/doc/html/boost/make_<wbr>recursive_variant=
..html</font></u></a></div><div>Unless I'm wrong, recursive variants current=
ly cannot contain a template type with non-type parameters, which is a bit =
annoying.&nbsp;This feature would make it possible.</div></div></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_613_1796018.1389397299857--

.
