相关疑难解决方法(0)

SFINAE并检测C++函数对象是否返回void

我已经阅读了有关这方面的各种权威,包括Dewhurst,但却没有设法通过这个看似简单的问题.

我想要做的是调用 C++ 函数对象(基本上,你可以调用的任何东西,纯函数或带()的类,并返回它的值,如果它不是void,否则返回"true".

using std:

struct Foo {
  void operator()() { cout << "Foo/"l; }
};
struct Bar {
  bool operator()() { cout << "Bar/"; return true; }
};

Foo foo;
Bar bar;
bool baz() { cout << "baz/"; return true; }
void bang() { cout << "bang/"; }

const char* print(bool b) { cout << b ? "true/" : "false/"; }

template <typename Functor> bool magicCallFunction(Functor f) {
  return true;  // Lots of template …
Run Code Online (Sandbox Code Playgroud)

c++ sfinae

7
推荐指数
2
解决办法
1968
查看次数

标签 统计

c++ ×1

sfinae ×1