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

Returns nth element in a sequence, or a default value. More...

Functions

template<typename = void>
auto coveo::linq::element_at_or_default (std::size_t n) -> detail::element_at_or_default_impl<>
 Returns nth element in sequence or default value. More...
 

Detailed Description

The element_at operator returns the nth element in the sequence. If the sequence does not have enough elements, a default value is returned instead.

This is a terminal operator.

.NET equivalent: ElementAtOrDefault

Function Documentation

◆ element_at_or_default()

template<typename = void>
auto coveo::linq::element_at_or_default ( std::size_t  n) -> detail::element_at_or_default_impl<>

Returns the nth element in a sequence. If the sequence does not have enough elements, a default-initialized value is returned instead.

Use like this:

const int NUMS[] = { 42, 23, 66 };
using namespace coveo::linq;
auto second = from(NUMS)
| element_at(1);
auto fourth = from(NUMS)
| element_at(3);
// second == 23
// fourth == 0
Parameters
n0-based index of element to return.
Returns
(Once applied) nth element in sequence or, if sequence does not have enough elements, a default value.