14 #ifndef COVEO_ENUMERABLE_H 15 #define COVEO_ENUMERABLE_H 17 #include "coveo/seq/sequence_util.h" 18 #include <coveo/seq/detail/enumerable_detail.h> 24 #include <type_traits> 112 using next_delegate = std::function<pointer()>;
121 using size_delegate = std::function<std::size_t()>;
170 typename _S = std::nullptr_t,
171 typename =
typename std::enable_if<!is_enumerable<
typename std::decay<F>::type>::value &&
172 (!detail::has_begin<
typename std::decay<F>::type>::value ||
173 !detail::has_end<
typename std::decay<F>::type>::value),
void>::type>
200 typename =
typename std::enable_if<!is_enumerable<
typename std::decay<C>::type>::value &&
201 detail::has_begin<
typename std::decay<C>::type>::value &&
202 detail::has_end<
typename std::decay<C>::type>::value,
void>::type>
216 typename =
typename std::enable_if<!std::is_const<U>::value &&
217 std::is_same<T,
typename std::add_const<U>::type>::value,
void>::type>
232 typename =
typename std::enable_if<!std::is_const<U>::value &&
233 std::is_same<T,
typename std::add_const<U>::type>::value,
void>::type>
313 return size_ !=
nullptr;
371 using iterator_category = std::forward_iterator_tag;
390 using raw_value_type =
typename enumerable<T>::raw_value_type;
398 using difference_type = std::ptrdiff_t;
421 mutable next_delegate next_;
422 mutable pointer pcur_ =
nullptr;
423 mutable bool has_cur_ =
true;
427 pointer get_pcur()
const {
704 template<
typename It>
762 typename =
typename std::enable_if<!std::is_reference<C>::value,
void>::type>
814 return enumerable<
typename seq_element_traits<U>::const_value_type>::for_one(std::forward<U>(obj));
831 return enumerable<T>::for_one_ref(obj);
847 template<
typename It>
851 return enumerable<
typename seq_element_traits<
decltype(*std::declval<It>())>::value_type>::for_range(
852 std::move(ibeg), std::move(iend));
873 return enumerable<
typename seq_element_traits<
decltype(*std::begin(std::declval<C>()))>::value_type>::for_container(
892 typename =
typename std::enable_if<!std::is_reference<C>::value,
void>::type>
896 return enumerable<
typename seq_element_traits<
decltype(*std::begin(std::declval<C>()))>::const_value_type>::for_container(
917 return enumerable<T>::for_array(parr, siz);
pointer operator->() const
Element pointer access.
Definition: enumerable.h:544
friend bool operator==(const iterator &left, const iterator &right)
Compares iterator for equality.
Definition: enumerable.h:594
static enumerable< T > for_container(C &&cnt)
Returns enumerable over container's sequence (stored internally).
Definition: enumerable.h:763
static enumerable< T > for_container(C &cnt)
Returns enumerable over container's sequence (stored externally).
Definition: enumerable.h:733
enumerable(F &&next, _S &&siz=nullptr)
Constructor with delegates.
Definition: enumerable.h:174
enumerable(C &&cnt)
Constructor with container.
Definition: enumerable.h:203
iterator operator++(int)
Moves to next element (post-increment).
Definition: enumerable.h:577
auto enumerate_one_ref(T &obj) -> enumerable< T >
Returns enumerable over sequence of one element (stored externally).
Definition: enumerable.h:830
Iterator for elements in the sequence.
Definition: enumerable.h:361
iterator & operator=(iterator &&obj)
Move assignment operator.
Definition: enumerable.h:508
auto 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).
Definition: enumerable.h:893
reference operator *() const
Element access.
Definition: enumerable.h:531
enumerable & operator=(enumerable< U > e)
Assignment operator for non-const to const conversion.
Definition: enumerable.h:234
static enumerable< T > empty()
Returns enumerable over empty sequence.
Definition: enumerable.h:628
iterator end() const
Iterator to end of sequence.
Definition: enumerable.h:281
auto enumerate_range(It ibeg, It iend) -> enumerable< typename seq_element_traits< decltype(*std::declval< It >())>::value_type >
Returns enumerable over sequence bound by iterators.
Definition: enumerable.h:848
auto as_const() const -> enumerable< typename std::add_const< T >::type >
Non-const to const explicit conversion.
Definition: enumerable.h:343
static enumerable< T > for_one(U &&obj)
Returns enumerable over sequence of one element (stored internally).
Definition: enumerable.h:647
iterator begin() const
Iterator to beginning of sequence.
Definition: enumerable.h:253
auto 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).
Definition: enumerable.h:870
static enumerable< T > for_array(pointer parr, size_t siz)
Returns enumerable over array's sequence.
Definition: enumerable.h:793
iterator cbegin() const
Alias for begin().
Definition: enumerable.h:267
Type-erased sequence wrapper.
Definition: enumerable.h:62
iterator(const enumerable< T > &parent, bool is_end)
Constructor from enumerable.
Definition: enumerable.h:455
iterator cend() const
Alias for end().
Definition: enumerable.h:295
enumerable()
Default constructor.
Definition: enumerable.h:149
static enumerable< T > for_range(It ibeg, It iend)
Returns enumerable over sequence bound by iterators.
Definition: enumerable.h:705
Traits class for elements in a sequence.
Definition: sequence_util.h:40
bool has_fast_size() const
Determines if size() is fast.
Definition: enumerable.h:311
iterator(iterator &&obj)
Move constructor.
Definition: enumerable.h:477
iterator & operator=(const iterator &obj)=default
Assignment operator.
friend bool operator!=(const iterator &left, const iterator &right)
Compares iterator for inequality.
Definition: enumerable.h:612
std::size_t size() const
Size of sequence.
Definition: enumerable.h:328
auto enumerate_one(U &&obj) -> enumerable< typename seq_element_traits< U >::const_value_type >
Returns enumerable over sequence of one element (stored internally).
Definition: enumerable.h:813
enumerable(enumerable< U > e)
Constructor for non-const to const conversion.
Definition: enumerable.h:218
auto enumerate_array(T *parr, size_t siz) -> enumerable< T >
Returns enumerable over array's sequence.
Definition: enumerable.h:916
iterator & operator++()
Moves to next element (pre-increment).
Definition: enumerable.h:557
iterator()=default
Default constructor.
iterator(const iterator &obj)=default
Copy constructor.
static enumerable< T > for_one_ref(reference obj)
Returns enumerable over sequence of one element (stored externally).
Definition: enumerable.h:676