Reputation: 3
e.g. I have the following Foo class with the foo() to check if all the types are std::int32_t
class Foo {
public:
/// check if all the types are std::int32_t
template<typename ...Ts>
bool foo() {
return true && std::is_same<Ts, std::int32_t>::value...;
}
};
int main()
{
Foo f;
std::cout<<f.template foo<std::int32_t, std::int32_t>(); //true
std::cout<<f.template foo<std::int32_t, std::int64_t>(); //false
return 0;
}
return true && std::is_same<Ts, std::int32_t>::value...;
is not a correct syntax. How do I make it correct?
Upvotes: 0
Views: 293
Reputation: 141748
https://en.cppreference.com/w/cpp/language/fold
return (true && ... && std::is_same<Ts, std::int32_t>::value);
# or
return (std::is_same<Ts, std::int32_t>::value && ... && true);
# or really just
return (std::is_same<Ts, std::int32_t>::value && ...);
Upvotes: 2