c++ - How to choose among similar functions from different namespaces based on template parameter -


the title , code self-explanatory,

is such thing possible?how?

is encouraged? if not, alternative? thanks

#include <iostream> using namespace std; namespace {  void foo()  {    cout << "in a\n";  } }  namespace b {  void foo()  {   cout << "in b\n";  } }   template <typename x> struct foo {     void foo()     {      x::foo();     } };   int main() {    foo<a> _foo;   _foo.foo();  return 0; } 

if rename member function, can find via adl using proxy tag:

namespace {     struct tag {};      void foo(tag)      {          std::cout << "in a\n";      } }  namespace b {     struct tag {};      void foo(tag)      {          std::cout << "in b\n";      } }  template<class tag> struct foo {     void fooadl()     {         foo(tag{});     } };  int main() {     foo<a::tag> f;     f.fooadl(); } 

Comments