I have a template template with a type parameter and an asymmetric template. I want to specialize a member function that I find, as in the example below, I can do a full specialization.
template<typename T, int R> struct foo { foo(const T& v) : value_(v) {} void bar() { std::cout << "Generic" << std::endl; for (int i = 0; i < R; ++i) std::cout << value_ << std::endl; } T value_; }; template<> void foo<float, 3>::bar() { std::cout << "Float" << std::endl; for (int i = 0; i < 3; ++i) std::cout << value_ << std::endl; }
However, this partial specialization will not compile.
template<int R> void foo<double, R>::bar() { std::cout << "Double" << std::endl; for (int i = 0; i < R; ++i) std::cout << value_ << std::endl; }
Is there a way to achieve what I'm trying, does anyone know? I tried this in MSVC 2010.
c ++ templates template-specialization partial-specialization
Eoin Apr 16 2018-11-11T00: 00Z
source share