Consider following
#include <iostream>
template <typename T, bool B>
struct C {
using value_type = T;
value_type f(value_type v);
};
template <bool B>
auto C<int, B>::f(value_type v) -> value_type {
return v;
}
int main(int argc, char * argv[]) {
C<int, true> c;
std::cout << c.f(5) << std::endl;
return 0;
}
Using g++ 4.9 I get error
test.cpp:11:26: error: 'C::f' declared as an 'inline' variable
inline auto C::f(value_type v) -> value_type {
test.cpp:11:26: error: template definition of non-template 'auto C::f'
test.cpp:11:26: error: 'value_type' was not declared in this scope
Problem is with value_type
. It will be working when I replace this with typename C<int, B>::value_type
but this is much longer and specially in real world applications it could be very long (my case). It there a way to make this work with short variant?
PS: It works with full template specialisation but I have to have only partial specialisation.