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

Performs a set intersection of two sequences. More...

Functions

template<typename Seq2 >
auto coveo::linq::intersect (Seq2 &&seq2) -> detail::intersect_impl< Seq2, detail::less<>>
 Performs set intersection of two sequences. More...
 
template<typename Seq2 , typename Pred >
auto coveo::linq::intersect (Seq2 &&seq2, Pred &&pred) -> detail::intersect_impl< Seq2, Pred >
 Performs set intersection of two sequences using predicate. More...
 

Detailed Description

The intersect operator returns all elements in the first sequence that are also found in the second sequence (essentially a set intersection). The elements are returned in the order that they appear in the first sequence.

.NET equivalent: Intersect

Function Documentation

◆ intersect() [1/2]

template<typename Seq2 >
auto coveo::linq::intersect ( Seq2 &&  seq2) -> detail::intersect_impl<Seq2, detail::less<>>

Returns a sequence containing all elements from the first source sequence that are also in the second source sequence (essentially a set intersection). Elements are returned in the order that they appear in the first sequence.

Elements are found using operator<() to compare them.

Use like this:

const int ONE[] = { 42, 23, 66, 11, 7, 67 };
const int TWO[] = { 10, 7, 60, 42, 43, 23 };
using namespace coveo::linq;
auto seq = from(ONE)
| intersect(TWO);
// seq = { 42, 23, 7 }
Parameters
seq2Second source sequence.
Returns
(Once applied) Sequence containing elements from first source sequence that are also in seq2.

◆ intersect() [2/2]

template<typename Seq2 , typename Pred >
auto coveo::linq::intersect ( Seq2 &&  seq2,
Pred &&  pred 
) -> detail::intersect_impl<Seq2, Pred>

Returns a sequence containing all elements from the first source sequence that are also in the second source sequence (essentially a set intersection). Elements are returned in the order that they appear in the first sequence.

Elements are found using the provided predicate to compare them. The predicate must provide a strict ordering of the elements, like std::less.

Use like this:

const int ONE[] = { 42, 23, 66, 11, 7, 67 };
const int TWO[] = { 10, 7, 60, 42, 43, 23 };
using namespace coveo::linq;
auto seq = from(ONE)
| intersect(TWO, [](int i, int j) { return i > j; });
// seq = { 42, 23, 7 }
Parameters
seq2Second source sequence.
predPredicate used to compare the elements.
Returns
(Once applied) Sequence containing elements from first source sequence that are also in seq2.