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

Returns maximum element in a sequence. More...

Functions

template<typename = void>
auto coveo::linq::max () -> detail::max_impl_0<>
 Returns maximum element in sequence. More...
 
template<typename Selector >
auto coveo::linq::max (const Selector &sel) -> detail::max_impl_1< Selector >
 Returns maximum projected value in sequence. More...
 

Detailed Description

The max operator returns the maximum element in a sequence. If the sequence does not have elements, an exception is thrown.

This is a terminal operator.

.NET equivalent: Max

Function Documentation

◆ max() [1/2]

template<typename = void>
auto coveo::linq::max ( ) -> detail::max_impl_0<>

Returns the maximum element in a sequence. If the sequence does not have elements, coveo::linq::empty_sequence is thrown.

Use like this:

const std::vector<int> YES = { 42, 23, 66, 11, 7 };
const std::vector<int> NAY;
using namespace coveo::linq;
auto max1 = from(YES)
| max();
// max1 == 66
// This throws an exception:
// auto max2 = from(NAY)
// | max();
Returns
(Once applied) Maximum element in sequence.
Exceptions
coveo::linq::empty_sequenceThe sequence does not have elements.

◆ max() [2/2]

template<typename Selector >
auto coveo::linq::max ( const Selector &  sel) -> detail::max_impl_1<Selector>

Returns the maximum value in a sequence by projecting each element to a different value using the provided selector. If the sequence does not have elements, coveo::linq::empty_sequence is thrown.

Use like this:

const std::vector<int> YES = { 42, 23, 66, 11, 7 };
const std::vector<int> NAY;
using namespace coveo::linq;
auto max1 = from(YES)
| max([](int i) { return -i; });
// max1 == -7
// This throws an exception:
// auto max2 = from(NAY)
// | max([](int i) { return -i; });
Parameters
selSelector called to project each element into a different value.
Returns
(Once applied) Maximum projected value in sequence.
Exceptions
coveo::linq::empty_sequenceThe sequence does not have elements.