假设我有一个std::tuple
:
std::tuple<Types...> myTuple;
// fill myTuple with stuff
现在我想知道 func
是否为 lambda 中的任何元素返回 true,其中 func
是某个 lambda,例如:
auto func = [](auto&& x) -> bool { return someOperation(x); }
我该怎么做?请注意,Types...
可能很大,因此我不想每次都遍历所有 元素。
最佳答案
#include <tuple>
std::tuple<int, char, double> myTuple{ 1, 'a', 3.14f };
bool result = std::apply([](auto&&... args) {
return (someOperation(decltype(args)(args)) || ...);
}
, myTuple);
关于c++ - 如何查找元素是否存在于元组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40233067/