coveo::linq
Implementation of .NET-like LINQ operators in C++
Functions

Checks if a sequence has elements. More...

Functions

template<typename = void>
auto coveo::linq::any () -> detail::any_impl_0<>
 Checks for any element. More...
 
template<typename Pred >
auto coveo::linq::any (const Pred &pred) -> detail::any_impl_1< Pred >
 Checks for any element that satisfy a predicate. More...
 

Detailed Description

The any operator checks if a sequence has elements, or if it has elements that satisfy a given predicate.

This is a terminal operator.

.NET equivalent: Any

Function Documentation

◆ any() [1/2]

template<typename = void>
auto coveo::linq::any ( ) -> detail::any_impl_0<>

Checks if a sequence has elements.

Use like this:

const std::vector<int> ONE = { 42, 23, 66 };
const std::vector<int> TWO;
using namespace coveo::linq;
bool one_any = from(ONE)
| any();
bool two_any = from(TWO)
| any();
// one_any == true
// two_any == false
Returns
(Once applied) true if sequence has at least one element.

◆ any() [2/2]

template<typename Pred >
auto coveo::linq::any ( const Pred &  pred) -> detail::any_impl_1<Pred>

Checks if a sequence has at least one element that satisfy a predicate. The predicate is called with each element and must return true if the element satisfy the predicate. The final result indicates if there's at least one element that satisfy the predicate.

Works on empty sequences (returns false in such a case).

Use like this:

const int NUMS = { 42, 23, 66 };
using namespace coveo::linq;
bool any_big = from(NUMS)
| any([](int i) { return i >= 90; });
bool any_odd = from(NUMS)
| any([](int i) { return i % 2 != 0; });
// any_big == false
// any_odd == true
Parameters
predPredicate to satisfy.
Returns
(Once applied) true if at least one element in sequence satisfies pred.