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

Returns nth element in a sequence. More...

Functions

template<typename = void>
auto coveo::linq::element_at (std::size_t n) -> detail::element_at_impl<>
 Returns nth element in sequence. More...
 

Detailed Description

The element_at operator returns the nth element in the sequence. If the sequence does not have enough elements, an exception is thrown.

This is a terminal operator.

.NET equivalent: ElementAt

Function Documentation

◆ element_at()

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

Returns the nth element in a sequence. If the sequence does not have enough elements, coveo::linq::out_of_range is thrown.

Use like this:

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