0
votes

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

1
Do you want to "switch" between backing container type at runtime (switch to vector as array grows beyond threshold) or are the (maximum) container sizes compile time constant expressions (as in your code example)? Please try to provide a (reduced, minimal) example that exhibits the same compilation error.Daniel Jour

1 Answers

3
votes

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.