Partial specialization of C ++ template

I cannot figure out how to specialize this template in part. the compiler complains that the template parameter N is not used in partial specialization

#include <boost/multi_array.hpp>

template<typename T, class A>
struct adaptable;

template<typename T, size_t N>
struct adaptable<T,
                 // line below is the problem
                 typename boost::multi_array<T,N>::template array_view<2>::type>
{
    typedef typename boost::multi_array<T,N>::template array_view<2>::type type;
};

I can add a template template parameter only to disable the compiler.

template<typename T, class A, class A0 = A>
struct adaptable;

template<typename T, size_t N>
struct adaptable<T,
                 typename boost::multi_array<T,N>::template array_view<2>::type,
                 boost::multi_array<T,N> >
{
    typedef typename boost::multi_array<T,N>::template array_view<2>::type type;
};

is there an easier way?

+3
source share
1 answer

I do not see in your example anything like partial specialization. A partial specialization is a specialization that sets the exact types for some, if the parameters of the base template, but leave others open. For instance:

template <class T, class U>
struct my_template {    
     // the base template where both T and U are generic
};

template <class T>
struct my_template<int> { 
    // A partial specialization where T is still generic, but U == int
};

( N). 1..N-1. , "" , . ( , ).

+3

Source: https://habr.com/ru/post/1758846/


All Articles