Standard C++17 implementation of vector any, all:
template<class C, class T>
bool contains(const C& c, const T& value) {
return std::find(c.begin(), c.end(), value) != c.end();
}
template<class C, class... T>
bool any(const C& c, T&&... value) {
return (... || contains(c, value));
}
template<class C, class... T>
bool all(const C& c, T&&... value) {
return (... && contains(c, value));
}
for usage as in
std::array<int, 6> data0 = { 4, 6, 8, 10, 12, 14 };
assert( any(data0, 10, 55, 792));
assert( !any(data0, 11));
assert( all(data0, 6, 14, 8));
assert( !all(data0, 6, 7, 8));
Is there an analogous way to define only, which returns true if and only if the set of unique values of the vector matches the input values? So the following asserts would hold
std::array<int, 6> data1 = { 1, 1, 2, 1, 2 };
assert( only(data1, 1, 2));
assert( !only(data1, 1));