如何检查一个类是否为它定义了operator <<?

时间:2019-01-31 16:20:58

标签: c++ template-meta-programming sfinae enable-if

如何检查std::cout << myClass;是否有效?我想做类似的事情:

class Logger {
 public:
  // Some kind of enable_if(operator<< doesn't exist)
  void printMyClass(MyClass& my_class) {
    std::cout << "Got a myclass" << std::endl;
  }   

  // Some kind of enable_if(operator<< exists)
  void printMyClass(MyClass& my_class) {
    std::cout << "Got a myclass: " << my_class << std::endl;
  }   

};

0 个答案:

没有答案