【发布时间】:2017-04-06 09:17:39
【问题描述】:
是否可以创建一种 std::enable_if_and_else,如 std::conditional 但没有未定义类的编译时错误。
这是一个例子:
static constexpr bool myExpr = true;
struct A {};
struct B;
struct C :
std::conditional<myExpr,
A,
B>::type
{}; // Compilation error: B is declared but not defined
struct D :
enable_if_else<myExpr,
A,
B>::type
{}; // It works
谢谢
【问题讨论】:
-
不应该
myExpr是true所以它需要A分支? -
是的,错误的复制和粘贴。你说得对。谢谢
-
无论如何,I cannot reproduce the error。你用的是什么编译器?
-
你说得对,我使用的代码不同。我试图做一个基本案例,但它似乎不同..我会再检查一次
标签: c++ c++11 template-meta-programming sfinae enable-if