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

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

Functions

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

Detailed Description

The union_with operator returns the union of all elements in the first and second sequence (essentially a set union). Similar to a concatenation, except duplicate elements are filtered out. The elements are returned in the order that they appear in the sequences.

.NET equivalent: Union

Function Documentation

◆ union_with() [1/2]

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

Returns a sequence containing all elements from the two source sequences (essentially a set union). Duplicate elements are filtered out. Elements are returned in the order that they appear in the sequences.

Elements are compared using operator<().

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)
| union_with(TWO);
// seq = { 42, 23, 66, 11, 7, 67, 10, 60, 43 }
Parameters
seq2Second source sequence.
Returns
(Once applied) Sequence containing all elements from first source sequence and from seq2.

◆ union_with() [2/2]

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

Returns a sequence containing all elements from the two source sequences (essentially a set union). Duplicate elements are filtered out. Elements are returned in the order that they appear in the sequences.

Elements are compared using the provided predicate. 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)
| union_with(TWO, [](int i, int j) { return i > j; });
// seq = { 42, 23, 66, 11, 7, 67, 10, 60, 43 }
Parameters
seq2Second source sequence.
predPredicate used to compare sequence elements.
Returns
(Once applied) Sequence containing all elements from first source sequence and from seq2.