I am tryng to specialize some traits (for instance std::is_arithmetic or assertion_traits in cppunit) for a template class (CRTP) that can hold a value of the template parameter type (something similar to BOOST_STRONG_TYPEDEF)
I try to use SFINAE to restrict my specialization
the sample code works fine with gcc6 and upper, but does not compile with Visual c++ (2015 or 2017)
error C2753: 'is_ar<T>': partial specialization cannot match argument list for primary template
or clang6
error: class template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list
the sample code:
template<class T, typename B>
struct Base
{
using typed_type = T ;
using base_type = B ;
base_type x;
};
template <typename T>
struct MyType
{
using base_type = T;
base_type x;
};
struct CRTPInt : Base<CRTPInt, int> { };
template <typename T>
struct is_ar
{
static const bool value = false;
};
template <>
struct is_ar<int>
{
static const bool value = true;
};
template <class T, typename...>
using typer = T;
template <typename T>
struct is_ar<typer<T, typename T::base_type, typename T::typed_type>> : is_ar<typename T::base_type>
{
static const bool value = true;
};
static_assert(is_arithmetic<CRTPInt>::value, "failed");
static_assert(is_arithmetic<CRTPInt::base_type>::value, "failed");
What did i do wrong ?
Is it valid c++11 ? How can I make it work with Visual C++ compiler ?
the answer from max66 work fine assuming that I can modify the initial definition of the trait. but in practice i would like to specialize framework traits (cppunit::assertion_traits for instance) for the class created by the macro
#define MY_TYPEDEF(type , base) struct type: Base<type , base> { };
the classes declared by this macro are not template classes so I do not find a way to specialize for all the classes generated this way.
The only common denominator beeing the typenames base_type and typed_type being defined.
Any Idea ?