Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using declaration for concrete output operator (with concrete signature)

Tags:

c++

namespaces

namespace nm
{
  class C1 {};
  class C2 {};
  inline std::ostream& operator << (std::ostream& lhs, std::vector<C1> const&) { return lhs; }
  inline std::ostream& operator << (std::ostream& lhs, std::vector<C2> const&) { return lhs; }
}

using nm::operator<<;

Is there way to declare to use only one of operators << from namespace nm in the global one, and not both?

like image 908
Роман Коптев Avatar asked Oct 20 '15 12:10

Роман Коптев


1 Answers

One solution would be to put each operator<< in its own nested name space:

namespace nm
{
  class C1 {};
  class C2 {};
  namespace nm1 {
    inline std::ostream& operator << (std::ostream& lhs, C1 const&) { return lhs; }
  }
  namespace nm2 {
    inline std::ostream& operator << (std::ostream& lhs, C2 const&) { return lhs; }
  }
}

using nm::nm1::operator<<;

LIVE DEMO

like image 59
101010 Avatar answered Oct 06 '22 02:10

101010