繁体   English   中英

std ::有条件的SFINAE

[英]std::conditional with SFINAE

是否可以创建某种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

谢谢

是否可以创建某种std :: enable_if_and_else,如std :: conditional,但对于未定义的类却没有编译时错误。

如果B不完整,则std::conditional<true, A, B>::type应该没有任何错误,因为您没有以要求B完整的方式使用B

所以std::conditional已经是您想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM