templates - Why can't enable_if be used on specialized parameter? -


i trying create partial specialization integral types. idea similar to:

#include <type_traits>  template <typename t> struct class { };  template <typename t> struct class<typename std::enable_if<std::is_integral<t>::value, t>::type> { }; 

this leads following error:

error: template parameters not deducible in partial specialization: struct class<typename std::enable_if<std::is_integral<t>::value, t>::type> {        ^ note: 't' 

it work if use template parameter:

#include <type_traits>  template <typename t, typename enable = void> struct class { };  template <typename t> struct class<t, typename std::enable_if<std::is_integral<t>::value>::type> { }; 

why need template parameter?

in first case not specializing class. when write:

template <typename t> struct class<typename std::enable_if<std::is_integral<t>::value, t>::type> { }; 

that t still generic template type, , compiler gets confused.

in second case, when write

template <typename t> struct class<t, typename std::enable_if<std::is_integral<t>::value>::type> { }; 

you correctly specialize template parameter enable, , works fine.

if want specialize first one, should type type, not want

template <> struct class<std::enable_if<std::is_integral<int>::value, int>::type> { }; 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -