是否可以创建一种 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
谢谢
最佳答案
Is it possible to create a sort of std::enable_if_and_else, like std::conditional but without the compile time errors for classes that are not defined.
std::conditional<true, A, B>::type
不应该有任何错误如果B
不完整,因为您没有使用 B
以一种要求它完整的方式。
所以 std::conditional
已经是您正在寻找的东西。
关于c++ - std::条件与 SFINAE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43250849/