For readability reasons, I would like to specialize a function template close to the definition of a class which is declared inside a namespace:
#include <iostream>
template<typename T> void my_function() {
std::cout << "my_function default" << std::endl;
}
namespace Nested {
class A {};
template<> void my_function<A>() {
std::cout << "my_function specialization for A" << std::endl;
}
}
However, with the above code I get the following error from clang++ 4.0:
error: no function template matches function template specialization 'my_function'
This seems to be a namespacing problem. How can I get the above to work (without moving the template function specialization out of the Nested
namespace)?
Edit: I have also tried adding ::my_function
in the specialization:
test.cpp: error: definition or redeclaration of 'my_function' cannot name the global scope
template<> void ::my_function<A>() {
~~^