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

Filters out duplicate elements in a sequence. More...

Functions

template<typename = void>
auto coveo::linq::distinct () -> detail::distinct_impl< detail::less<>>
 Filters out duplicate elements in sequence. More...
 
template<typename Pred >
auto coveo::linq::distinct (Pred &&pred) -> detail::distinct_impl< Pred >
 Filters out duplicate elements in sequence using predicate. More...
 

Detailed Description

The distinct operator filters out duplicate elements in a sequence. Unique elements are returned in the same order they appear in the source sequence.

.NET equivalent: Distinct

Function Documentation

◆ distinct() [1/2]

template<typename = void>
auto coveo::linq::distinct ( ) -> detail::distinct_impl<detail::less<>>

Filters out duplicate elements in a sequence, returning the unique elements in the same order they appear in the source sequence.

To filter out duplicates, elements are sorted using operator<().

Use like this:

const int NUMS[] = { 42, 23, 11, 66, 11, 42, 7, 66, 67 };
using namespace coveo::linq;
auto seq = from(NUMS)
| distinct();
// seq = { 42, 23, 11, 66, 7, 67 }
Returns
(Once applied) Sequence containing all unique elements from source sequence.

◆ distinct() [2/2]

template<typename Pred >
auto coveo::linq::distinct ( Pred &&  pred) -> detail::distinct_impl<Pred>

Filters out duplicate elements in a sequence, returning the unique elements in the same order they appear in the source sequence.

To filter out duplicates, the provided predicate is used to sort the elements. The predicate must provide a strict ordering of the elements, like std::less.

Use like this:

const int NUMS[] = { 42, 23, 11, 66, 11, 42, 7, 66, 67 };
using namespace coveo::linq;
auto seq = from(NUMS)
| distinct([](int i, int j) { return i > j; });
// seq = { 42, 23, 11, 66, 7, 67 }
Parameters
predPredicate used to order the elements in order to remove the duplicates.
Returns
(Once applied) Sequence containing all unique elements from source sequence.