How can I find if an element exists in a tuple?

c++, c++14, tuples

Solution

#include <tuple>

std::tuple<int, char, double> myTuple{ 1, 'a', 3.14f };

bool result = std::apply([](auto&&... args) {
                           return (someOperation(decltype(args)(args)) || ...);
                         }
                       , myTuple);

DEMO

Problem

Suppose I have a `std::tuple`: ``` std::tuple<Types...> myTuple; // fill myTuple with stuff ``` Now I want to find if `func` returns true for any element in the lambda, where `func` is some lambda, e.g.: ``` auto func = [](auto&& x) -> bool { return someOperation(x); } ``` How can I do this? Note that `Types...` may be large so I don't want to iterate over all elements every time.

Original source

Related problems