enable_if method specialization

前端 未结 3 810
栀梦
栀梦 2020-12-28 20:36
template
struct A
{
    A operator%( const T& x);
};

template
A A::operator%( const T& x ) {          


        
3条回答
  •  感情败类
    2020-12-28 21:11

    You can also use a default boolean template parameter like this:

    template
    struct A
    {
        T x;
    
        A( const T& _x ) : x(_x) {}
    
        template
        typename std::enable_if::value && EnableBool, A >::type 
        operator% ( const T& right ) const
        {
            return A(fmod(x, right));
        }
    
        template
        typename std::enable_if::value && EnableBool, A >::type 
        operator% ( const T& right ) const
        {
            return A(x%right);
        }
    };
    

提交回复
热议问题