Vio*_*ffe 0 c++ templates c++17
我想要做的很简单:在一个可变的类模板中,我想检查类型的一些编译时条件.在这种情况下,我想知道包装中是否有某种类型.这就是C++ 17的折叠表达式可能看起来的代码,但显然这不是有效的语法.怎么实现呢?
#include <type_traits>
template <class... Types>
struct TypesPack
{
    template <typename T>
    static constexpr bool hasType() {
        return std::is_same<T, Types>::value || ... || false;
    }
};
Run Code Online (Sandbox Code Playgroud)
    static constexpr bool hasType() {
    return (std::is_same<T, Types>::value || ...);
}
Run Code Online (Sandbox Code Playgroud)
fold-expression必须用括号括起来,并且允许false在||用作运算符时省略.