Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can template alias be used for partial specialization?

Given a template alias

template<unsigned U>
using uint_ = integral_constant<unsigned,U>;

The partial specialization of

template<class T,class P>
struct size{};

as

template <class T,unsigned U>
struct size<T,uint_<U>>{};

generates a warning astemplate parameter can not be deduced for clang 3.1 while no warning is generated with gcc 4.7

So, is it malformed code?

like image 459
abir Avatar asked Feb 19 '23 09:02

abir


2 Answers

The code is perfectly fine in C++11. The Clang's warning can be ignored.

like image 69
Nawaz Avatar answered Feb 21 '23 22:02

Nawaz


Another guy said that this is a Clang bug. You can work it around if you change the using declaration like this

template<unsigned T, unsigned U = T>
using uint_ = integral_constant<unsigned,U>;

As an educated guess, apparently Clang does not correctly update the identity of the template parameter that appears in the type-id. So it thinks in your example that the resulting type uint_<U> refers to the first parameter of the partial specialization (because within uint_ that is the case, but not in the point of use). Alternatively you can exchange the order at the point of use

template <unsigned U,class T>
struct size<T,uint_<U>>{};
like image 22
Johannes Schaub - litb Avatar answered Feb 21 '23 23:02

Johannes Schaub - litb