use*_*392 1 c++ sfinae enable-if template-meta-programming c++11
是否可以创建某种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
Run Code Online (Sandbox Code Playgroud)
谢谢
是否可以创建某种std :: enable_if_and_else,如std :: conditional,但没有针对未定义类的编译时错误。
std::conditional<true, A, B>::type如果B不完整,应该没有任何错误,因为您使用B的方式不完整。
因此std::conditional,您已经在寻找什么。
| 归档时间: |
|
| 查看次数: |
459 次 |
| 最近记录: |