apramc
apramc

Reputation: 1386

partial template specialization error

I am writing a container class that for sizes smaller that a threshold uses std::array as a kernel and larger sizes uses std::vector.

here is my implementaiton.

    template<typename, size_t, bool>
    class VectorStorage {
    };

    template<typename T, size_t DIM>
class VectorStorage<T, DIM, bool_const_v<(DIM < threshold)> > : public kernel_t<T,
        DIM, 1> { // impelementaion}

template<typename T, size_t DIM>
class VectorStorage<T, DIM, bool_const_v<(DIM >= threshold)> > : public kernel_t<T,
        DIM, 1> { // impelementaion}

I get the following error ? is it even possible to do this given that SFINAE doen't work for clas specialiaziton ? I am using clang with -std=c++1y

non-type template argument depends on a template parameter of the partial specialization

Upvotes: 0

Views: 89

Answers (1)

T.C.
T.C.

Reputation: 137394

Put the computation into a default template argument.

template<typename T, size_t DIM, bool ISSMALL = (DIM < threshold)>
class VectorStorage {
   /* default implementation for small case */
};

template<typename T, size_t DIM>
class VectorStorage<T, DIM, false> {
   /* implementation for big case */
};

You can also switch them around, or use two partial specializations. Add a wrapper if you are paranoid and want to hide ISSMALL.

Upvotes: 3

Related Questions