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

Filters a sequence. More...

Functions

template<typename Pred >
auto coveo::linq::where (Pred &&pred) -> detail::where_impl< detail::indexless_selector_proxy< Pred >>
 Filters sequence elements using predicate. More...
 
template<typename Pred >
auto coveo::linq::where_with_index (Pred &&pred) -> detail::where_impl< Pred >
 Filters sequence elements using predicate and element index. More...
 

Detailed Description

The where operator (and its siblings) filter the elements in a sequence, returning a new sequence containing only the elements that satisfy a predicate.

.NET equivalent: Where

Function Documentation

◆ where()

template<typename Pred >
auto coveo::linq::where ( Pred &&  pred) -> detail::where_impl<detail::indexless_selector_proxy<Pred>>

Returns a sequence that contains only the elements from the source sequence that satisfy the given predicate. Order of the elements is preserved.

Use like this:

const int NUMS[] = { 42, 23, 66, 11, 7 };
using namespace coveo::linq;
auto seq = from(NUMS)
| where([](int i) { return i % 2 != 0; });
// seq = { 23, 11, 7 }
Parameters
predPredicate to satisfy.
Returns
(Once applied) Sequence containing all elements from source sequence for which pred returned true.

◆ where_with_index()

template<typename Pred >
auto coveo::linq::where_with_index ( Pred &&  pred) -> detail::where_impl<Pred>

Returns a sequence that contains only the elements from the source sequence that satisfy the given predicate. Order of the elements is preserved.

The predicate receives two arguments: a sequence element and its position in the sequence.

Use like this:

const int NUMS[] = { 42, 23, 66, 11, 7 };
using namespace coveo::linq;
auto seq = from(NUMS)
| where_with_index([](int i, std::size_t idx) { return i % 2 != 0 || idx == 0; });
// seq = { 42, 23, 11, 7 }
Parameters
predPredicate to satisfy.
Returns
(Once applied) Sequence containing all elements from source sequence for which pred returned true.