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

Utilities used by coveo::enumerable. More...

Go to the source code of this file.

Classes

struct  coveo::seq_element_traits< T >
 Traits class for elements in a sequence. More...
 
struct  coveo::seq_traits< Seq >
 Traits class for a sequence. More...
 
struct  coveo::is_enumerable< T >
 Traits class to identify enumerable objects. More...
 

Functions

template<typename C , typename Seq >
auto coveo::try_reserve (C &cnt, const Seq &seq) -> typename std::enable_if< is_enumerable< Seq >::value, bool >::type
 Helper function to quickly reserve space in a container if possible. More...
 
template<typename Seq >
auto coveo::try_get_size_delegate (const Seq &seq) -> typename std::enable_if< is_enumerable< Seq >::value, std::function< std::size_t()>>::type
 Helper function to get a fast size delegate if possible. More...
 
template<typename It >
auto coveo::try_get_size_delegate_for_iterators (const It &beg, const It &end) -> typename std::enable_if< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< It >::iterator_category >::value, std::function< std::size_t()>>::type
 Helper function to get a fast size delegate from iterators if possible. More...
 

Detailed Description

Function Documentation

◆ try_reserve()

template<typename C , typename Seq >
auto coveo::try_reserve ( C &  cnt,
const Seq &  seq 
) -> typename std::enable_if<is_enumerable<Seq>::value, bool>::type

Attempts to reserve space in container cnt to hold as many elements as found in sequence seq. This is performed only if it's possible to do so "quickly".

Parameters
cntContainer in which to reserve space.
seqSequence to use to try to reserve space for.
Returns
true if space has actually been reserved in cnt.

◆ try_get_size_delegate()

template<typename Seq >
auto coveo::try_get_size_delegate ( const Seq &  seq) -> typename std::enable_if<is_enumerable<Seq>::value, std::function<std::size_t()>>::type

Attempts to create a coveo::enumerable::size_delegate that can quickly calculate the number of elements found in sequence seq. A size delegate is returned only if it's possible to calculate the number of elements "quickly".

  • If seq is a coveo::enumerable, its coveo::enumerable::size() method is used to produce the size delegate if coveo::enumerable::has_fast_size() returns true.
  • If seq is a container with a size() method, a size delegate is produced using that method.
  • If seq is a sequence that uses random-access iterators, a size delegate is produced by using std::distance().
  • Otherwise, no size delegate is produced.
Parameters
seqSequence to calculate the number of elements of in order to produce the size delegate.
Returns
coveo::enumerable::size_delegate instance, or nullptr if it's not possible to quickly calculate the number of elements in seq.
See also
coveo::enumerable::size_delegate

◆ try_get_size_delegate_for_iterators()

template<typename It >
auto coveo::try_get_size_delegate_for_iterators ( const It &  beg,
const It &  end 
) -> typename std::enable_if<std::is_base_of<std::random_access_iterator_tag, typename std::iterator_traits<It>::iterator_category>::value, std::function<std::size_t()>>::type

Attempts to create a coveo::enumerable::size_delegate that can quickly calculate the number of elements in range [beg, end[. A size delegate is returned only if it's possible to calculate the number of elements "quickly".

  • If beg and end are random-access iterators, a size delegate is produced by using std::distance().
  • Otherwise, no size delegate is produced.
Parameters
begIterator pointing at beginning of range.
endIterator pointing at end of range.
Returns
coveo::enumerable::size_delegate instance, or nullptr if it's not possible to quickly calculate the number of elements in [beg, end[
See also
coveo::enumerable::size_delegate