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

Compares two sequences. More...

Functions

template<typename Seq2 >
auto coveo::linq::sequence_equal (const Seq2 &seq2) -> detail::sequence_equal_impl_1< Seq2 >
 Compares elements in two sequences. More...
 
template<typename Seq2 , typename Pred >
auto coveo::linq::sequence_equal (const Seq2 &seq2, const Pred &pred) -> detail::sequence_equal_impl_2< Seq2, Pred >
 Compares elements in two sequences using predicate. More...
 

Detailed Description

The sequence_equal operator compares two sequences and validates that they contain the same elements.

This is a terminal operator.

.NET equivalent: SequenceEqual

Function Documentation

◆ sequence_equal() [1/2]

template<typename Seq2 >
auto coveo::linq::sequence_equal ( const Seq2 &  seq2) -> detail::sequence_equal_impl_1<Seq2>

Scans two sequences and compares each corresponding element using operator==(). Returns true if the two sequences contain the same elements in the same order.

Use like this:

const int NUMS1 = { 42, 23, 66 };
const std::vector<int> NUMS2 = { 42, 23, 66 };
const std::vector<int> NUMS3 = { 67, 11, 7 };
using namespace coveo::linq;
bool one_and_two = from(NUMS1)
| sequence_equal(NUMS2);
bool one_and_three = from(NUMS1)
| sequence_equal(NUMS3);
// one_and_two == true
// one_and_three == false
Parameters
seq2Second sequence to compare. The first sequence is the one on which the operator will be applied (e.g., the sequence passed to coveo::linq::from()).
Returns
(Once applied) true both sequences contain the same elements in the same order.

◆ sequence_equal() [2/2]

template<typename Seq2 , typename Pred >
auto coveo::linq::sequence_equal ( const Seq2 &  seq2,
const Pred &  pred 
) -> detail::sequence_equal_impl_2<Seq2, Pred>

Scans two sequences and compares each corresponding element using the provided predicate. Returns true if the two sequences contain the same elements in the same order.

Use like this:

const int NUMS1 = { 42, 23, 66 };
const std::vector<int> NUMS2 = { 41, 24, 67 };
const std::vector<int> NUMS3 = { 30, 30, 90 };
auto fuzzy_equal = [](int i, int j) { return std::abs(i - j) <= 2; };
using namespace coveo::linq;
bool one_and_two = from(NUMS1)
| sequence_equal(NUMS2, fuzzy_equal);
bool one_and_three = from(NUMS1)
| sequence_equal(NUMS3, fuzzy_equal);
// one_and_two == true
// one_and_three == false
Parameters
seq2Second sequence to compare. The first sequence is the one on which the operator will be applied (e.g., the sequence passed to coveo::linq::from()).
predPredicate used to compare the elements.
Returns
(Once applied) true both sequences contain the same elements in the same order.