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

Looks for an element in a sequence. More...

Functions

template<typename T >
auto coveo::linq::contains (const T &obj) -> detail::contains_impl_1< T >
 Look for element in a sequence. More...
 
template<typename T , typename Pred >
auto coveo::linq::contains (const T &obj, const Pred &pred) -> detail::contains_impl_2< T, Pred >
 Look for element in a sequence using a predicate. More...
 

Detailed Description

The contains operator determines if a sequence contains a specific element.

This is a terminal operator.

.NET equivalent: Contains

Function Documentation

◆ contains() [1/2]

template<typename T >
auto coveo::linq::contains ( const T &  obj) -> detail::contains_impl_1<T>

Scans a sequence, looking for the provided element. Elements are compared using operator==().

Use like this:

const int NUMS[] = { 42, 23, 66 };
using namespace coveo::linq;
auto has_42 = from(NUMS)
| contains(42);
auto has_67 = from(NUMS)
| contains(67);
// has_42 == true
// has_67 == false
Parameters
objElement to look for.
Returns
(Once applied) true if obj was found in sequence.

◆ contains() [2/2]

template<typename T , typename Pred >
auto coveo::linq::contains ( const T &  obj,
const Pred &  pred 
) -> detail::contains_impl_2<T, Pred>

Scans a sequence, looking for the provided element. Elements are compared using the provided predicate.

Use like this:

const int NUMS[] = { 42, 23, 66 };
auto fuzzy_equal = [](int i, int j) { return std::abs(i - j) <= 2; };
using namespace coveo::linq;
auto has_67 = from(NUMS)
| contains(67, fuzzy_equal);
auto has_11 = from(NUMS)
| contains(11, fuzzy_equal);
// has_67 == true
// has_11 == false
Parameters
objElement to look for.
predPredicate used to compare the elements. Always receives obj as its second argument.
Returns
(Once applied) true if obj was found in sequence.