I cant figure out how to specialize partially this template. compiler complains that 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 dummy template parameter just to silence 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 more straightforward way?
struct adapatable
look like? – Omnifariousadaptable
, the 2nd template parameter is a type, while in your specialisation, it is an integral constant. My guess is that for that reason, the 2nd declaration is not actually a specialisation (partial or otherwise) of the 1st, and should probably be flagged by the compiler as an error. – j_random_hackerA
andN
is apparently too obscure to be allowed. An analogue with types is the way that you can specialize atemplate<class T> struct X
forT
of the formvector<U>
(for allU
) but not forT
of the formvector<U>::iterator
. And of course the same thing is true when deducing the template arguments of functions, though I don't know enough C++ to say whether the rules are exactly the same :) – Mike Dinsdaletypename boost::multi_array<T,N>::template array_view<2>::type
is a "non-deduced context" forN
. Although it seems like if you were to try to instantiateadaptable<float, typename boost::multi_array<float,42>::template array_view<2>::type>
, the compiler should be able to deduceN
= 42, it makes sense to forbid this type of deduction because in general it (a) doesn't necessarily have a unique answer (e.g.N
= 123 might also give the same ultimate type) and (b) even if it does, that unique answer could be extremely hard to find. – j_random_hacker