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

Ensures a sequence has at least one element. More...

Functions

template<typename = void>
auto coveo::linq::default_if_empty () -> detail::default_if_empty_impl_0<>
 Ensures sequence has at least one element. More...
 
template<typename T >
auto coveo::linq::default_if_empty (const T &obj) -> detail::default_if_empty_impl_1< T >
 Ensures sequence has at least one element, specifying said element. More...
 

Detailed Description

The default_if_empty operator either returns the source sequence or, if that sequence is empty, a new sequence with a single, default element.

.NET equivalent: DefaultIfEmpty

Function Documentation

◆ default_if_empty() [1/2]

template<typename = void>
auto coveo::linq::default_if_empty ( ) -> detail::default_if_empty_impl_0<>

Either returns the source sequence or, if that sequence is empty, a new sequence containing a single, default element.

Use like this:

const std::vector<int> THREE = { 42, 23, 66 };
const std::vector<int> EMPTY;
using namespace coveo::linq;
auto seq1 = from(THREE)
auto seq2 = from(EMPTY)
// seq1 == { 42, 23, 66 }
// seq2 == { 0 }
Returns
(Once applied) Source sequence, or sequence with single, default element.

◆ default_if_empty() [2/2]

template<typename T >
auto coveo::linq::default_if_empty ( const T &  obj) -> detail::default_if_empty_impl_1<T>

Either returns the source sequence or, if that sequence is empty, a new sequence containing the provided default element.

Use like this:

const std::vector<int> THREE = { 42, 23, 66 };
const std::vector<int> EMPTY;
using namespace coveo::linq;
auto seq1 = from(THREE)
auto seq2 = from(EMPTY)
// seq1 == { 42, 23, 66 }
// seq2 == { 11 }
Parameters
objDefault element to use if sequence is empty.
Returns
(Once applied) Source sequence, or sequence with single element obj.