How should I initialize a static variable for a partial specialization?
template <bool A=true, bool B=false>
struct from {
const static std::string value;
};
// no specialization - works
template <bool A, bool B>
const std::string from<A, B>::value = "";
// partial specialization - does not compile -
// Error: template argument list following class template name must list parameters in the order used in template parameter list
// Error: from<A,B>' : too few template arguments
template <bool B>
const std::string from<true, B>::value = "";
// full specialization - works
const std::string from<false, true>::value = "";
Why doesn't the partial work?
EDIT: I found a solution based on Partial template specialization for initialization of static data members of template classes
I need to repeat the declaration for the partial specialization before it allowed me to initialize the static variable:
template <bool B>
struct from<true, B> {
const static std::string value;
};
Again, the question is why?