coveo::linq
Implementation of .NET-like LINQ operators in C++
Classes | Functions
enumerable.h File Reference

C++ implementation of .NET's IEnumerable-like data structure. More...

Go to the source code of this file.

Classes

class  coveo::enumerable< T >
 Type-erased sequence wrapper. More...
 
class  coveo::enumerable< T >::iterator
 Iterator for elements in the sequence. More...
 

Functions

template<typename U >
auto coveo::enumerate_one (U &&obj) -> enumerable< typename seq_element_traits< U >::const_value_type >
 Returns enumerable over sequence of one element (stored internally). More...
 
template<typename T >
auto coveo::enumerate_one_ref (T &obj) -> enumerable< T >
 Returns enumerable over sequence of one element (stored externally). More...
 
template<typename It >
auto coveo::enumerate_range (It ibeg, It iend) -> enumerable< typename seq_element_traits< decltype(*std::declval< It >())>::value_type >
 Returns enumerable over sequence bound by iterators. More...
 
template<typename C >
auto coveo::enumerate_container (C &cnt) -> enumerable< typename seq_element_traits< decltype(*std::begin(std::declval< C >()))>::value_type >
 Returns enumerable over container's sequence (stored externally). More...
 
template<typename C , typename = typename std::enable_if<!std::is_reference<C>::value, void>::type>
auto coveo::enumerate_container (C &&cnt) -> enumerable< typename seq_element_traits< decltype(*std::begin(std::declval< C >()))>::const_value_type >
 Returns enumerable over container's sequence (stored internally). More...
 
template<typename T >
auto coveo::enumerate_array (T *parr, size_t siz) -> enumerable< T >
 Returns enumerable over array's sequence. More...
 

Detailed Description

This file contains the definition of coveo::enumerable, which is a wrapper for a sequence similar to .NET's IEnumerable<T>. Also includes helper methods and functions to create enumerables from single values, containers, etc.

Function Documentation

◆ enumerate_one()

template<typename U >
auto coveo::enumerate_one ( U &&  obj) -> enumerable<typename seq_element_traits<U>::const_value_type>

Returns a coveo::enumerable over a sequence of one element. The enumerable will store the element internally, moving it if possible.

The enumerable's type is deduced from the type of the element.

Parameters
objObject to store as the sequence's only element.
Returns
enumerable over sequence of one element.
See also
coveo::enumerable::for_one()

◆ enumerate_one_ref()

template<typename T >
auto coveo::enumerate_one_ref ( T &  obj) -> enumerable<T>

Returns a coveo::enumerable over a sequence of one element. The enumerable will only store a reference to the element.

The enumerable's type is deduced from the type of the element.

Parameters
objObject to use as the sequence's only element.
Returns
enumerable over sequence of one element.
See also
coveo::enumerable::for_one_ref()

◆ enumerate_range()

template<typename It >
auto coveo::enumerate_range ( It  ibeg,
It  iend 
) -> enumerable<typename seq_element_traits<decltype(*std::declval<It>())>::value_type>

Returns a coveo::enumerable over a sequence bound by two iterators.

The enumerable's type is deduced from the type of element returned by the iterators.

Parameters
ibegIterator pointing at beginning of range.
iendIterator pointing at end of range.
Returns
enumerable over sequence bound by [ibeg, iend[.
See also
coveo::enumerable::for_range()

◆ enumerate_container() [1/2]

template<typename C >
auto coveo::enumerate_container ( C &  cnt) -> enumerable<typename seq_element_traits<decltype(*std::begin(std::declval<C>()))>::value_type>

Returns a coveo::enumerable over a sequence stored in a container. Only a reference to the container is kept by the enumerable.

The enumerable's type is deduced from the type of elements stored in the container.

Parameters
cntContainer whose elements to wrap.
Returns
enumerable over sequence of elements from cnt.
See also
coveo::enumerable::for_container()

◆ enumerate_container() [2/2]

template<typename C , typename = typename std::enable_if<!std::is_reference<C>::value, void>::type>
auto coveo::enumerate_container ( C &&  cnt) -> enumerable<typename seq_element_traits<decltype(*std::begin(std::declval<C>()))>::const_value_type>

Returns a coveo::enumerable over a sequence stored in a container. The container is moved to the enumerable and stored internally.

The enumerable's type is deduced from the type of elements stored in the container.

Parameters
cntContainer to store in the enumerable.
Returns
enumerable over sequence of elements from cnt.
See also
coveo::enumerable::for_container()

◆ enumerate_array()

template<typename T >
auto coveo::enumerate_array ( T *  parr,
size_t  siz 
) -> enumerable<T>

Returns a coveo::enumerable over a sequence stored in a dynamic array. Equivalent to using coveo::enumerate_range() without using pointer arithmetic.

The enumerable's type is deduced from the type of elements stored in the array.

Parameters
parrPointer to beginning of array.
sizSize of array.
Returns
enumerable over sequence in array.
See also
coveo::enumerable::for_array()