我确定必须可以将SFINAE(可能与宏一起)用于static_assert(),以便任意代码可以not进行编译。
我的代码库中有一些复杂的情况,我有一个我想禁止使用临时类的类(我相信模式是:]]
class(const class&& tmp)=delete; /* deny copying from an unnamed temporary */ class (class&& rhs){/* allow construction from non-temporary rvalue*/}
当前,我检查了不需要的构造函数,但不进行编译,但是随后我必须注释掉它,以使测试再次进行编译!
如果可以的话:
static_assert(DOES_NOT_COMPILE(myclass_t("Hello"))); const char* help = "HELP"; static_assert(!DOES_NOT_COMPILE(myclass_t(help))); // COMPILES() might be better here :-)
这将对我有很大帮助,但是我似乎找不到通用的SFINAE解决方案。仅适用于C ++ 14,因此:
if constexpr
不可用。
我确信必须可以将SFINAE(可能与宏一起)用于static_assert(),从而无法编译任意代码。我的代码库中有一些复杂的情况,其中我有一个类...
以下宏使您可以以对SFINAE友好的方式重写对SFINAE不友好的表达式,例如[](auto&&x) { return x+1; }
。
以@Yakk的答案为基础,我发现这很棒。我们永远都希望[]
RETURNS(void( blah ))