Topic: A new is_specialized type trait


Author: Morwenn <morwenn29@gmail.com>
Date: Mon, 27 Jul 2015 04:11:46 -0700 (PDT)
Raw View
------=_Part_3113_1663110262.1437995506673
Content-Type: multipart/alternative;
 boundary="----=_Part_3114_663983676.1437995506673"

------=_Part_3114_663983676.1437995506673
Content-Type: text/plain; charset=UTF-8

A some point in one of my projects, I needed a tait to check whether a
template was specialized for a given type to use it if it was and fall back
to another template if it wasn't. Therefore, I wrote a small is_specialized
trait class to do the job in the vein of the detection toolkit:

    template<
        template<typename...> class,
        typename,
        typename=void    >    struct is_specialized:
        std::false_type    {};
    template<
        template<typename...> class Template,
        typename T    >    struct is_specialized<Template, T, std::void_t<decltype(Template<T>{})>>:
        std::true_type    {};

Would such an addition to the standard header <type_traits> be useful for general-purpose specialization detection?




--

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

<div dir=3D"ltr">A some point in one of my projects, I needed a tait to che=
ck whether a template was specialized for a given type to use it if it was =
and fall back to another template if it wasn&#39;t. Therefore, I wrote a sm=
all <span style=3D"font-family: courier new,monospace;">is_specialized</spa=
n> trait class to do the job in the vein of the detection toolkit:<br><br><=
pre style=3D"" class=3D"lang-cpp prettyprint prettyprinted"><code><span cla=
ss=3D"kwd">    template</span><span class=3D"pun">&lt;</span><span class=3D=
"pln">
        </span><span class=3D"kwd">template</span><span class=3D"pun">&lt;<=
/span><span class=3D"kwd">typename</span><span class=3D"pun">...&gt;</span>=
<span class=3D"pln"> </span><span class=3D"kwd">class</span><span class=3D"=
pun">,</span><span class=3D"pln">
        </span><span class=3D"kwd">typename</span><span class=3D"pun">,</sp=
an><span class=3D"pln">
        </span><span class=3D"kwd">typename</span><span class=3D"pun">=3D</=
span><span class=3D"kwd">void</span><span class=3D"pln">
</span><span class=3D"pun">    &gt;</span><span class=3D"pln">
</span><span class=3D"kwd">    struct</span><span class=3D"pln"> is_special=
ized</span><span class=3D"pun">:</span><span class=3D"pln">
        std</span><span class=3D"pun">::</span><span class=3D"pln">false_ty=
pe
</span><span class=3D"pun">    {};</span><span class=3D"pln">

</span><span class=3D"kwd">    template</span><span class=3D"pun">&lt;</spa=
n><span class=3D"pln">
        </span><span class=3D"kwd">template</span><span class=3D"pun">&lt;<=
/span><span class=3D"kwd">typename</span><span class=3D"pun">...&gt;</span>=
<span class=3D"pln"> </span><span class=3D"kwd">class</span><span class=3D"=
pln"> </span><span class=3D"typ">Template</span><span class=3D"pun">,</span=
><span class=3D"pln">
    </span><span class=3D"kwd">    typename</span><span class=3D"pln"> T
</span><span class=3D"pun">    &gt;</span><span class=3D"pln">
</span><span class=3D"kwd">    struct</span><span class=3D"pln"> is_special=
ized</span><span class=3D"pun">&lt;</span><span class=3D"typ">Template</spa=
n><span class=3D"pun">,</span><span class=3D"pln"> T</span><span class=3D"p=
un">,</span><span class=3D"pln"> std</span><span class=3D"pun">::</span><sp=
an class=3D"typ">void_t</span><span class=3D"pun">&lt;</span><span class=3D=
"kwd">decltype</span><span class=3D"pun">(</span><span class=3D"typ">Templa=
te</span><span class=3D"pun">&lt;</span><span class=3D"pln">T</span><span c=
lass=3D"pun">&gt;{})&gt;&gt;:</span><span class=3D"pln">
        std</span><span class=3D"pun">::</span><span class=3D"pln">true_typ=
e
</span><span class=3D"pun">    {};</span></code><br><code><span class=3D"pu=
n"></span></code><code><span class=3D"pun"><br><span style=3D"font-family: =
arial,sans-serif;">Would such an addition to the standard header <span styl=
e=3D"font-family: courier new,monospace;">&lt;type_traits&gt;</span> be use=
ful for general-purpose specialization detection?</span><br></span></code><=
/pre><br><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_3114_663983676.1437995506673--
------=_Part_3113_1663110262.1437995506673--

.


Author: David Krauss <potswa@gmail.com>
Date: Mon, 27 Jul 2015 19:20:07 +0800
Raw View
--Apple-Mail=_4B174B8A-F2A8-48F5-BA66-88BBC07B7068
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9307=E2=80=9327, at 7:11 PM, Morwenn <morwenn29@gmail.com> =
wrote:
>=20
> A some point in one of my projects, I needed a tait to check whether a te=
mplate was specialized for a given type to use it if it was and fall back t=
o another template if it wasn't. Therefore, I wrote a small is_specialized =
trait class to do the job in the vein of the detection toolkit:

This is stateful metaprogramming, which the committee tends to oppose.

I=E2=80=99d be interested to take the enclosing project as a case study, be=
cause I have a solution to a very similar problem. There=E2=80=99s a defect=
 report which will make it ill-formed, but I don=E2=80=99t think it=E2=80=
=99s too dangerous, and there=E2=80=99s a significant potential to reduce b=
loat and complexity. (is_specialized is an example of something that is dan=
gerous, because its value varies during interpretation of the TU.)

Here is my utility:

namespace impl {
 template< typename ... key >
 struct static_state_entry {
  template< typename value, bool enable >
  class payload {
   friend auto resolve_static_state( static_state_entry< key ... > ) { retu=
rn payload{}; }
   typedef value type;
  };
  template< typename value >
  class payload< value, false > {};
 =09
  friend auto resolve_static_state( static_state_entry< key ... > );
 };
}
template< bool enable, typename value, typename ... key >
using static_set_if =3D decltype(void( typename impl::static_state_entry< k=
ey ... >::template payload< value, enable >{} ));
template< typename value, typename ... key >
using static_set =3D static_set_if< true, value, key ... >;

template< typename ... key >
using static_get =3D typename decltype( resolve_static_state( impl::static_=
state_entry< key ... >{} ) )::type;


Rather than check whether the template was specialized for a given type, th=
is allows a type to nominate itself as the preferred specialization of a te=
mplate. There must be exactly one such type, and it must nominate itself be=
fore anyone else queries the nominated type.

--=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=_4B174B8A-F2A8-48F5-BA66-88BBC07B7068
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""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9307=
=E2=80=9327, at 7:11 PM, Morwenn &lt;<a href=3D"mailto:morwenn29@gmail.com"=
 class=3D"">morwenn29@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-inte=
rchange-newline"><div class=3D""><div dir=3D"ltr" class=3D"">A some point i=
n one of my projects, I needed a tait to check whether a template was speci=
alized for a given type to use it if it was and fall back to another templa=
te if it wasn't. Therefore, I wrote a small <span style=3D"font-family: cou=
rier new,monospace;" class=3D"">is_specialized</span> trait class to do the=
 job in the vein of the detection toolkit:<br class=3D""></div></div></bloc=
kquote><div><br class=3D""></div>This is stateful metaprogramming, which th=
e committee tends to oppose.</div><div><br class=3D""></div><div>I=E2=80=99=
d be interested to take the enclosing project as a case study, because I ha=
ve a solution to a very similar problem. There=E2=80=99s a defect report wh=
ich will make it ill-formed, but I don=E2=80=99t think it=E2=80=99s too dan=
gerous, and there=E2=80=99s a significant potential to reduce bloat and com=
plexity. (<font face=3D"Courier" class=3D"">is_specialized</font> is an exa=
mple of something that is dangerous, because its value varies during interp=
retation of the TU.)</div><div><br class=3D""></div><div>Here is my utility=
:</div><div><br class=3D""></div><div><div><font face=3D"Courier" class=3D"=
">namespace impl {</font></div><div><font face=3D"Courier" class=3D""><span=
 class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>template&lt; ty=
pename ... key &gt;</font></div><div><font face=3D"Courier" class=3D""><spa=
n class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>struct static_=
state_entry {</font></div><div><font face=3D"Courier" class=3D""><span clas=
s=3D"Apple-tab-span" style=3D"white-space:pre">  </span>template&lt; typena=
me value, bool enable &gt;</font></div><div><font face=3D"Courier" class=3D=
""><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>class =
payload {</font></div><div><font face=3D"Courier" class=3D""><span class=3D=
"Apple-tab-span" style=3D"white-space:pre">   </span>friend auto resolve_st=
atic_state( static_state_entry&lt; key ... &gt; ) { return payload{}; }</fo=
nt></div><div><font face=3D"Courier" class=3D""><span class=3D"Apple-tab-sp=
an" style=3D"white-space:pre">   </span>typedef value type;</font></div><di=
v><font face=3D"Courier" class=3D""><span class=3D"Apple-tab-span" style=3D=
"white-space:pre">  </span>};</font></div><div><font face=3D"Courier" class=
=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>tem=
plate&lt; typename value &gt;</font></div><div><font face=3D"Courier" class=
=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>cla=
ss payload&lt; value, false &gt; {};</font></div><div><span class=3D"Apple-=
tab-span" style=3D"white-space:pre"><font face=3D"Courier" class=3D"">  </f=
ont></span></div><div><font face=3D"Courier" class=3D""><span class=3D"Appl=
e-tab-span" style=3D"white-space:pre">  </span>friend auto resolve_static_s=
tate( static_state_entry&lt; key ... &gt; );</font></div><div><font face=3D=
"Courier" class=3D""><span class=3D"Apple-tab-span" style=3D"white-space:pr=
e"> </span>};</font></div><div><font face=3D"Courier" class=3D"">}</font></=
div><div><font face=3D"Courier" class=3D"">template&lt; bool enable, typena=
me value, typename ... key &gt;</font></div><div><font face=3D"Courier" cla=
ss=3D"">using static_set_if =3D decltype(void( typename impl::static_state_=
entry&lt; key ... &gt;::template payload&lt; value, enable &gt;{} ));</font=
></div><div><font face=3D"Courier" class=3D"">template&lt; typename value, =
typename ... key &gt;</font></div><div><font face=3D"Courier" class=3D"">us=
ing static_set =3D static_set_if&lt; true, value, key ... &gt;;</font></div=
><div><font face=3D"Courier" class=3D""><br class=3D""></font></div><div><f=
ont face=3D"Courier" class=3D"">template&lt; typename ... key &gt;</font></=
div><div><font face=3D"Courier" class=3D"">using static_get =3D typename de=
cltype( resolve_static_state( impl::static_state_entry&lt; key ... &gt;{} )=
 )::type;</font></div><div class=3D""><br class=3D""></div></div><div><br c=
lass=3D""></div><div>Rather than check whether the template was specialized=
 for a given type, this allows a type to nominate itself as the preferred s=
pecialization of a template. There must be exactly one such type, and it mu=
st nominate itself before anyone else queries the nominated type.</div><div=
><br class=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=_4B174B8A-F2A8-48F5-BA66-88BBC07B7068--

.


Author: Morwenn <morwenn29@gmail.com>
Date: Mon, 27 Jul 2015 04:41:48 -0700 (PDT)
Raw View
------=_Part_255_775793237.1437997308736
Content-Type: multipart/alternative;
 boundary="----=_Part_256_539399717.1437997308736"

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

Le lundi 27 juillet 2015 13:20:18 UTC+2, David Krauss a =C3=A9crit :
>
>
> This is stateful metaprogramming, which the committee tends to oppose.
>

I didn't think of it like that, but you're right, it indeed allows stateful=
=20
metaprogramming and I remember reading a few articles and some discussions=
=20
here about how the committee wanted to get rid of it.
=20

> I=E2=80=99d be interested to take the enclosing project as a case study, =
because I=20
> have a solution to a very similar problem. There=E2=80=99s a defect repor=
t which=20
> will make it ill-formed, but I don=E2=80=99t think it=E2=80=99s too dange=
rous, and there=E2=80=99s=20
> a significant potential to reduce bloat and complexity. (is_specialized=
=20
> is an example of something that is dangerous, because its value varies=20
> during interpretation of the TU.)
>

Ok, it's been less than one hour, but I found a better solution to my=20
problem meanwhile. You know how it is: you have a problem, you think of=20
many tools, you pick one because it seems to be the best one, you develop=
=20
it, you share it and *then* you reaize that there was another solution and=
=20
that you were just blind for days until you tried the other ones. So,=20
unfortunately my use case wasn't valid since there was a better solution=20
available, so I don't feel the need to share it here, sorry :/

On the other hand, is_specialized was easy to develop, easy to use and asy=
=20
to understand, so I thought it was too simple to be dangerous before you=20
pointed to stateful metaprogramming.

You utility is interesting, I will keep it in a corner of my mind in case I=
=20
need something similar someday :)

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

<div dir=3D"ltr">Le lundi 27 juillet 2015 13:20:18 UTC+2, David Krauss a =
=C3=A9crit=C2=A0:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D=
"word-wrap:break-word"><div><div><br></div>This is stateful metaprogramming=
, which the committee tends to oppose.</div></div></blockquote><div><br>I d=
idn&#39;t think of it like that, but you&#39;re right, it indeed allows sta=
teful metaprogramming and I remember reading a few articles and some discus=
sions here about how the committee wanted to get rid of it.<br>=C2=A0</div>=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:break-=
word"><div>I=E2=80=99d be interested to take the enclosing project as a cas=
e study, because I have a solution to a very similar problem. There=E2=80=
=99s a defect report which will make it ill-formed, but I don=E2=80=99t thi=
nk it=E2=80=99s too dangerous, and there=E2=80=99s a significant potential =
to reduce bloat and complexity. (<font face=3D"Courier">is_specialized</fon=
t> is an example of something that is dangerous, because its value varies d=
uring interpretation of the TU.)</div></div></blockquote><div style=3D"word=
-wrap:break-word"><br>Ok, it&#39;s been less than one hour, but I found a b=
etter solution to my problem meanwhile. You know how it is: you have a prob=
lem, you think of many tools, you pick one because it seems to be the best =
one, you develop it, you share it and *then* you reaize that there was anot=
her solution and that you were just blind for days until you tried the othe=
r ones. So, unfortunately my use case wasn&#39;t valid since there was a be=
tter solution available, so I don&#39;t feel the need to share it here, sor=
ry :/<br><br>On the other hand, is_specialized was easy to develop, easy to=
 use and asy to understand, so I thought it was too simple to be dangerous =
before you pointed to stateful metaprogramming.<br><br>You utility is inter=
esting, I will keep it in a corner of my mind in case I need something simi=
lar someday :)<br><div><br></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 />

------=_Part_256_539399717.1437997308736--
------=_Part_255_775793237.1437997308736--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Mon, 27 Jul 2015 15:44:35 -0700 (PDT)
Raw View
------=_Part_1411_1125784689.1438037075459
Content-Type: multipart/alternative;
 boundary="----=_Part_1412_586445083.1438037075460"

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

On Monday, July 27, 2015 at 4:11:46 AM UTC-7, Morwenn wrote:
>
> A some point in one of my projects, I needed a tait to check whether a=20
> template was specialized for a given type to use it if it was and fall ba=
ck=20
> to another template if it wasn't. Therefore, I wrote a small=20
> is_specialized trait class to do the job in the vein of the detection=20
> toolkit:
>
>     template<
>         template<typename...> class,
>         typename,
>         typename=3Dvoid    >    struct is_specialized:
>         std::false_type    {};
>     template<
>         template<typename...> class Template,
>         typename T    >    struct is_specialized<Template, T, std::void_t=
<decltype(Template<T>{})>>:
>         std::true_type    {};
>
> Would such an addition to the standard header <type_traits> be useful for=
 general-purpose specialization detection?
>
>
I'm glad you've found a better solution to your problem. But I don't=20
understand the worse solution!
Surely the code above merely checks whether Template<T> is well-formed (and=
=20
constructible from an empty braced-initializer).
I don't see how it does anything to check whether Template<T> comes from a=
=20
specialization (either full or partial).

For example, I see

    static_assert(is_specialized<std::vector, int>::value);
    static_assert(is_specialized<std::vector, bool>::value);

Are you trying to find some construct that would return true for=20
vector<bool> and false for vector<int>?
And if so, why??

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

On Monday, July 27, 2015 at 4:11:46 AM UTC-7, Morwenn wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr">A some point in one of my pr=
ojects, I needed a tait to check whether a template was specialized for a g=
iven type to use it if it was and fall back to another template if it wasn&=
#39;t. Therefore, I wrote a small <span style=3D"font-family:courier new,mo=
nospace">is_specialized</span> trait class to do the job in the vein of the=
 detection toolkit:<br><br><pre><code><span>    template</span><span>&lt;</=
span><span>
        </span><span>template</span><span>&lt;</span><span>typename</span><=
span>...&gt;</span><span> </span><span>class</span><span>,</span><span>
        </span><span>typename</span><span>,</span><span>
        </span><span>typename</span><span>=3D</span><span>void</span><span>
</span><span>    &gt;</span><span>
</span><span>    struct</span><span> is_specialized</span><span>:</span><sp=
an>
        std</span><span>::</span><span>false_type
</span><span>    {};</span><span>

</span><span>    template</span><span>&lt;</span><span>
        </span><span>template</span><span>&lt;</span><span>typename</span><=
span>...&gt;</span><span> </span><span>class</span><span> </span><span>Temp=
late</span><span>,</span><span>
    </span><span>    typename</span><span> T
</span><span>    &gt;</span><span>
</span><span>    struct</span><span> is_specialized</span><span>&lt;</span>=
<span>Template</span><span>,</span><span> T</span><span>,</span><span> std<=
/span><span>::</span><span>void_t</span><span>&lt;</span><span>decltype</sp=
an><span>(</span><span>Template</span><span>&lt;</span><span>T</span><span>=
&gt;{})&gt;&gt;:</span><span>
        std</span><span>::</span><span>true_type
</span><span>    {};</span></code><br><code><span></span></code><code><span=
><br><span style=3D"font-family:arial,sans-serif">Would such an addition to=
 the standard header <span style=3D"font-family:courier new,monospace">&lt;=
type_traits&gt;</span> be useful for general-purpose specialization detecti=
on?</span></span></code></pre></div></blockquote><div><br></div><div>I&#39;=
m glad you&#39;ve found a better solution to your problem. But I don&#39;t =
understand the worse solution!</div><div>Surely the code above merely check=
s whether Template&lt;T&gt; is well-formed (and constructible from an empty=
 braced-initializer).</div><div>I don&#39;t see how it does anything to che=
ck whether Template&lt;T&gt; comes from a specialization (either full or pa=
rtial).</div><div><br></div><div>For example, I see</div><div><br></div><di=
v>=C2=A0 =C2=A0 static_assert(is_specialized&lt;std::vector, int&gt;::value=
);</div><div><div>=C2=A0 =C2=A0 static_assert(is_specialized&lt;std::vector=
, bool&gt;::value);</div></div><div><br></div><div>Are you trying to find s=
ome construct that would return true for vector&lt;bool&gt; and false for v=
ector&lt;int&gt;?</div><div>And if so, why??</div><div><br></div><div>=E2=
=80=93Arthur</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_1412_586445083.1438037075460--
------=_Part_1411_1125784689.1438037075459--

.


Author: Morwenn <morwenn29@gmail.com>
Date: Tue, 28 Jul 2015 15:16:59 -0700 (PDT)
Raw View
------=_Part_836_499982284.1438121819983
Content-Type: multipart/alternative;
 boundary="----=_Part_837_467369060.1438121819983"

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

Le mardi 28 juillet 2015 00:44:35 UTC+2, Arthur O'Dwyer a =C3=A9crit :
>
> I'm glad you've found a better solution to your problem. But I don't=20
> understand the worse solution!
> Surely the code above merely checks whether Template<T> is well-formed=20
> (and constructible from an empty braced-initializer).
> I don't see how it does anything to check whether Template<T> comes from =
a=20
> specialization (either full or partial).
>
> For example, I see
>
>     static_assert(is_specialized<std::vector, int>::value);
>     static_assert(is_specialized<std::vector, bool>::value);
>
> Are you trying to find some construct that would return true for=20
> vector<bool> and false for vector<int>?
> And if so, why??
>
> =E2=80=93Arthur
>

The sad truth is that you're right all the way down: it was actually=20
nothing more than a check for well-formedness (does that word even exist?).=
=20
For some reason, in my mind it was something different and represented=20
another concept but it does not. Sorry, I realized a while after that I was=
=20
only wasting my and everyone's time and actually feel pretty stupid about=
=20
it. It wasn't meant to detect whether there was an explicit specialization,=
=20
only that a specialization was well-formed but we indeed do not need a=20
trait for that ince we can check that for any template. For some reason I=
=20
was wearing specialization goggles when looking at the problem and created=
=20
something that did not really make sense.

Sorry for the non-problem -_____-

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

Le mardi 28 juillet 2015 00:44:35 UTC+2, Arthur O&#39;Dwyer a =C3=A9crit=C2=
=A0:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;"><div></div><div>I&#39;m gl=
ad you&#39;ve found a better solution to your problem. But I don&#39;t unde=
rstand the worse solution!</div><div>Surely the code above merely checks wh=
ether Template&lt;T&gt; is well-formed (and constructible from an empty bra=
ced-initializer).</div><div>I don&#39;t see how it does anything to check w=
hether Template&lt;T&gt; comes from a specialization (either full or partia=
l).</div><div><br></div><div>For example, I see</div><div><br></div><div>=
=C2=A0 =C2=A0 static_assert(is_specialized&lt;std::vector, int&gt;::value);=
</div><div><div>=C2=A0 =C2=A0 static_assert(is_specialized&lt;std::vector, =
bool&gt;::value);</div></div><div><br></div><div>Are you trying to find som=
e construct that would return true for vector&lt;bool&gt; and false for vec=
tor&lt;int&gt;?</div><div>And if so, why??</div><div><br></div><div>=E2=80=
=93Arthur</div></blockquote><div><br>The sad truth is that you&#39;re right=
 all the way down: it was actually nothing more than a check for well-forme=
dness (does that word even exist?). For some reason, in my mind it was some=
thing different and represented another concept but it does not. Sorry, I r=
ealized a while after that I was only wasting my and everyone&#39;s time an=
d actually feel pretty stupid about it. It wasn&#39;t meant to detect wheth=
er there was an explicit specialization, only that a specialization was wel=
l-formed but we indeed do not need a trait for that ince we can check that =
for any template. For some reason I was wearing specialization goggles when=
 looking at the problem and created something that did not really make sens=
e.<br><br>Sorry for the non-problem -_____-<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_837_467369060.1438121819983--
------=_Part_836_499982284.1438121819983--

.


Author: "'Johannes Schaub' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 29 Jul 2015 00:22:50 +0200
Raw View
2015-07-27 13:11 GMT+02:00 Morwenn <morwenn29@gmail.com>:
> A some point in one of my projects, I needed a tait to check whether a
> template was specialized for a given type to use it if it was and fall back
> to another template if it wasn't. Therefore, I wrote a small is_specialized
> trait class to do the job in the vein of the detection toolkit:
>
>     template<
>         template<typename...> class,
>         typename,
>         typename=void
>     >
>     struct is_specialized:
>         std::false_type
>     {};
>
>     template<
>         template<typename...> class Template,
>         typename T
>     >
>     struct is_specialized<Template, T,
> std::void_t<decltype(Template<T>{})>>:
>         std::true_type
>     {};
>
> Would such an addition to the standard header <type_traits> be useful for
> general-purpose specialization detection?
>

I was in a situation like that aswell and I wrote the template for a
certain single template whose name I did know and tried to access the
injected class name instead

   `class Template<T>::Template`

This has the benefit that it works for all non-union classes. It still
only works if the non-specialized case is not defined. Unfortunately
it only works if you know the actual template name.

--

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

.