220 8238 <f4ec2cca-5951-447f-a938-0b2e5e3e233f@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Vincent Reverdy <vince.rev@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: A new keyword for either a type or a variable
 (typical use case for variadic template template)?
Date: Tue, 24 Dec 2013 15:32:57 -0800 (PST)
Lines: 153
Approved: news@gmane.org
Message-ID: <f4ec2cca-5951-447f-a938-0b2e5e3e233f@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_2534_30025635.1387927977605"
X-Trace: ger.gmane.org 1387927975 4140 80.91.229.3 (24 Dec 2013 23:32:55 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 24 Dec 2013 23:32:55 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCYPFAORZMKRBK5T5CKQKGQEY2L2JZI@isocpp.org Wed Dec 25 00:33:02 2013
Return-path: <std-proposals+bncBCYPFAORZMKRBK5T5CKQKGQEY2L2JZI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pb0-f71.google.com ([209.85.160.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCYPFAORZMKRBK5T5CKQKGQEY2L2JZI@isocpp.org>)
	id 1VvbTB-0002ct-GZ
	for gclcip-std-proposals@m.gmane.org; Wed, 25 Dec 2013 00:33:01 +0100
Original-Received: by mail-pb0-f71.google.com with SMTP id uo5sf19510064pbc.6
        for <gclcip-std-proposals@m.gmane.org>; Tue, 24 Dec 2013 15:33:00 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id: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=AqjpOejnyzbi32+GvlPIbcPpgQKjf7AfftgnVPCVPI8=;
        b=irBeTRhn8jlFfl2+Magk+DURxtck/MVaWwNnpbv5dx9oGN00cS8V1RZKiPKMRD2nwj
         k7TpiRG1M5VfaEHx+ftVq6XGV2OeuHqP7mQP5IFKBZ87xBOU522uPXir4TGvgHk6MZmu
         aA4TUdF7cLOlUtbkzm1Eo9U06gNyKmhxynQlYDriXbdAxPgEDrdjpaYz+Rp34dDkmhl9
         Od6fXqMA5m5GeqV8KgOMlJtuVccYHCjSmFmluoZdD3PoeFxRt4t8TjiiXGL8Vb2UbrIc
         eBnnhzpsUx2K9NxgLfK5dQFGRIPMnf92DUzxMTTQb+AzTvv/9Q+YKSb9+yIKddgkuz8U
         H2Mg==
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: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=AqjpOejnyzbi32+GvlPIbcPpgQKjf7AfftgnVPCVPI8=;
        b=ZywsizfYSQBT4BRf3GT3pDVtvUs/OBhCiDSDTr+gh0tkB558qDrMS6pdMBLown4dZF
         99/XEYU5IcJRbdc4Nn3IOBhp8+tDPdo2SEOXfqdxxelKu+MzRhJgmhb+dEp2ODshJ9Wl
         3oa38uXZiqQUxynM7NP31+p4VfC+vyI4ZJeWm/jN8do5NfZd7+Pu/g7mTu7F4s1KybmC
         O8ucf8NBO41+jKc1l6PIcFPMmUE7Pbj4qskXVIsUCOImNfntY9A46nv1KkpD1k4WkCsX
         5r1+hvAeXpDXLfeGoYKy8W6tKXOjrkfmIoz0FWCD26w2bHjp2z4/4O5Ezepfqbzov1ex
         8T+Q==
X-Gm-Message-State: ALoCoQnxMBgqP5ds0NswxOBHw9WmgEezZK3VZ6EzLruX2dQuliNfsdQ7rjSHoRwFcTRAD9G7bTpd
X-Received: by 10.67.14.70 with SMTP id fe6mr13434672pad.15.1387927980333;
        Tue, 24 Dec 2013 15:33:00 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.106.70 with SMTP id gs6ls2127954qeb.17.gmail; Tue, 24 Dec
 2013 15:32:59 -0800 (PST)
X-Received: by 10.49.116.169 with SMTP id jx9mr451124qeb.0.1387927979650;
        Tue, 24 Dec 2013 15:32:59 -0800 (PST)
X-Original-Sender: vince.rev@gmail.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:8238
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8238>

------=_Part_2534_30025635.1387927977605
Content-Type: text/plain; charset=ISO-8859-1

Hi, 

Currently, it is impossible, as far as I know, to write a "
is_specialization_of" helper struct to detect whether a type is a 
specialization of a given template.
It can be illustrated with the following example:
----------------------------------------------------------------------
#include <iostream>
#include <type_traits>
#include <tuple>
#include <vector>
#include <array>

template <template <class...> class Template, class T>
struct is_specialization_of 
: std::false_type {};
 
template <template <class...> class Template, class... Args>
struct is_specialization_of<Template, Template<Args...>> 
: std::true_type {};

int main()
{
    std::cout<<is_specialization_of<std::tuple,  
std::tuple<double>>::value<<::std::endl;
    std::cout<<is_specialization_of<std::vector, 
std::tuple<double>>::value<<::std::endl;
    std::cout<<is_specialization_of<std::array,  
std::tuple<double>>::value<<::std::endl; // Error
    return 0;
}
----------------------------------------------------------------------
It works well for templates of the form template <class...> but it fails 
for mixed type/variable template like std::array.
I think that it would be great (particularly for template metaprogramming) 
to have a a new keyword (whose name has to be defined) to declare "a type 
or a variable".
With this new keyword, one could type:
----------------------------------------------------------------------
#include <iostream>
#include <type_traits>
#include <tuple>
#include <vector>
#include <array>

template <template <keyword...> class Template, class T>
struct is_specialization_of 
: std::false_type {};
 
template <template <keyword...> class Template, keyword... Args>
struct is_specialization_of<Template, Template<keyword...>> 
: std::true_type {};

int main()
{
    std::cout<<is_specialization_of<std::tuple,  
std::tuple<double>>::value<<::std::endl;
    std::cout<<is_specialization_of<std::vector, 
std::tuple<double>>::value<<::std::endl;
    std::cout<<is_specialization_of<std::array,  
std::tuple<double>>::value<<::std::endl; // Ok
    return 0;
}
----------------------------------------------------------------------

Has it been already discussed? 
If not, what is you opinion about such a thing?
If yes, what were the issues?
Do you have any suggestion for the name of this keyword?

Thank you!

Vincent R.

-- 

--- 
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_2534_30025635.1387927977605
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi, <br><br>Currently, it is impossible, as far as I know,=
 to write a "<span style=3D"font-family: courier new,monospace;">is_special=
ization_of</span>" helper struct to detect whether a type is a specializati=
on of a given template.<br>It can be illustrated with the following example=
:<br><span style=3D"font-family: courier new,monospace;">------------------=
----------------------------------------------------</span><br><span style=
=3D"font-family: courier new,monospace;">#include &lt;iostream&gt;<br>#incl=
ude &lt;type_traits&gt;<br>#include &lt;tuple&gt;<br>#include &lt;vector&gt=
;<br>#include &lt;array&gt;<br><br>template &lt;template &lt;class...&gt; c=
lass Template, class T&gt;<br>struct is_specialization_of <br>: std::false_=
type {};<br>&nbsp;<br>template &lt;template &lt;class...&gt; class Template=
, class... Args&gt;<br>struct is_specialization_of&lt;Template, Template&lt=
;Args...&gt;&gt; <br>: std::true_type {};<br><br>int main()<br>{<br>&nbsp;&=
nbsp;&nbsp; std::cout&lt;&lt;is_specialization_of&lt;std::tuple,&nbsp; std:=
:tuple&lt;double&gt;&gt;::value&lt;&lt;::std::endl;<br>&nbsp;&nbsp;&nbsp; s=
td::cout&lt;&lt;is_specialization_of&lt;std::vector, std::tuple&lt;double&g=
t;&gt;::value&lt;&lt;::std::endl;<br>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;is=
_specialization_of&lt;std::array,&nbsp; std::tuple&lt;double&gt;&gt;::value=
&lt;&lt;::std::endl; // Error<br>&nbsp;&nbsp;&nbsp; return 0;<br>}</span><b=
r><span style=3D"font-family: courier new,monospace;">---------------------=
-------------------------------------------------</span><br>It works well f=
or templates of the form <span style=3D"font-family: courier new,monospace;=
">template &lt;class...&gt;</span> but it fails for mixed type/variable tem=
plate like <span style=3D"font-family: courier new,monospace;">std::array</=
span>.<br>I think that it would be great (particularly for template metapro=
gramming) to have a a new keyword (whose name has to be defined) to declare=
 "a type or a variable".<br>With this new keyword, one could type:<br><span=
 style=3D"font-family: courier new,monospace;">----------------------------=
------------------------------------------</span><br><span style=3D"font-fa=
mily: courier new,monospace;">#include &lt;iostream&gt;<br>#include &lt;typ=
e_traits&gt;<br>#include &lt;tuple&gt;<br>#include &lt;vector&gt;<br>#inclu=
de &lt;array&gt;<br><br>template &lt;template &lt;keyword...&gt; class Temp=
late, class T&gt;<br>struct is_specialization_of <br>: std::false_type {};<=
br>&nbsp;<br>template &lt;template &lt;keyword...&gt; class Template, keywo=
rd... Args&gt;<br>struct is_specialization_of&lt;Template, Template&lt;keyw=
ord...&gt;&gt; <br>: std::true_type {};<br><br>int main()<br>{<br>&nbsp;&nb=
sp;&nbsp; std::cout&lt;&lt;is_specialization_of&lt;std::tuple,&nbsp; std::t=
uple&lt;double&gt;&gt;::value&lt;&lt;::std::endl;<br>&nbsp;&nbsp;&nbsp; std=
::cout&lt;&lt;is_specialization_of&lt;std::vector, std::tuple&lt;double&gt;=
&gt;::value&lt;&lt;::std::endl;<br>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;is_s=
pecialization_of&lt;std::array,&nbsp; std::tuple&lt;double&gt;&gt;::value&l=
t;&lt;::std::endl; // Ok<br>&nbsp;&nbsp;&nbsp; return 0;<br>}</span><br><sp=
an style=3D"font-family: courier new,monospace;">--------------------------=
--------------------------------------------</span><br><br>Has it been alre=
ady discussed? <br>If not, what is you opinion about such a thing?<br>If ye=
s, what were the issues?<br>Do you have any suggestion for the name of this=
 keyword?<br><br>Thank you!<br><br>Vincent R.<br><br></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_2534_30025635.1387927977605--

.
