kblib 0.2.3
General utilities library for modern C++
iterators.h File Reference

This file provides some iterators, ranges, iterator/range adapters, and operations that can be performed on iterators or smart pointers. More...

#include "enumerate-contrib-cry.h"
#include "enumerate-contrib-tw.h"
#include "fakestd.h"
#include "traits.h"
#include <cassert>
#include <iterator>
#include <vector>
#include <optional>
Include dependency graph for iterators.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  kblib::to_pointer_impl< ptr >
 
struct  kblib::to_pointer_impl< T * >
 
struct  kblib::is_output_iterator_for< T, E, typename >
 Determine if T is a valid output iterator to which values of type E may be written. More...
 
struct  kblib::is_output_iterator_for< T, E, void_t< decltype(*std::declval< T & >()++=std::declval< const E & >())> >
 
class  kblib::counting_back_insert_iterator< Container >
 Like a std::back_insert_iterator, but it keeps track of how many insertions it has made, allowing an end iterator to be created. More...
 
struct  kblib::counting_back_insert_iterator< Container >::proxy_iterator
 
class  kblib::range_t< Value, Delta >
 A range generator, similar to Python 3's range(). More...
 
struct  kblib::range_t< Value, Delta >::iterator
 A helper struct which acts as an iterator for the range elements, as they are generated on the fly. More...
 
struct  kblib::detail_iterators::is_addable< T, U, typename >
 
struct  kblib::detail_iterators::is_addable< T, U, void_t< decltype(std::declval< T & >()+std::declval< U & >())> >
 
struct  kblib::adjuster
 
struct  kblib::incrementer
 A struct which increments anything it is added to. Suitable for use as a Delta type for range_t. More...
 
struct  kblib::decrementer
 A struct which decrements anything it is added to. Suitable for use as a Delta type for range_t. More...
 
class  kblib::irange_t< Value, Delta >
 
struct  kblib::detail_enumerate::force_copy_tag
 
class  kblib::enumeration< T >
 
class  std::tuple_size<::kblib::enumeration< T > >
 
class  std::tuple_element< 0, ::kblib::enumeration< T > >
 
class  std::tuple_element< 0, volatile ::kblib::enumeration< T > >
 
class  std::tuple_element< 0, const volatile ::kblib::enumeration< T > >
 
class  std::tuple_element< 1, volatile ::kblib::enumeration< T > >
 references keep the same qualifications as the original More...
 
class  std::tuple_element< 1, const volatile ::kblib::enumeration< T > >
 but you can also add const to a reference More...
 
class  std::tuple_element< 1, ::kblib::enumeration< T > >
 copies decay away the const More...
 
class  std::tuple_element< 1, const ::kblib::enumeration< T > >
 unless const is explicitly added More...
 
class  kblib::enumerator_iterator< It >
 
class  kblib::enumerator_t< Range, void >
 
class  kblib::enumerator_t< It, EndIt >
 
struct  kblib::indirect_range< Iter1, Iter2 >
 Allow range-for iteration of an iterator pair. More...
 
class  kblib::multi_range< Iter1, EndIter, count >
 
class  kblib::multi_range< Iter1, EndIter, 0 >
 
struct  kblib::containing_ptr< T >
 A smart pointer to an object contained inside the smart pointer object. More...
 
class  kblib::transform_iterator< base_iterator, operation >
 An InputIterator that applies a transformation to the elements of the range. More...
 
struct  kblib::zip_iterator< InputIt1, EndIt, InputIt2 >
 
struct  kblib::zip_iterator< It1, It1, It2 >
 
class  kblib::adjacent_iterator< ForwardIt, EndIt >
 TODO(killerbee13): Implement adjacent_iterator. More...
 
class  kblib::back_insert_iterator_F< Container, F >
 An OutputIterator that transforms the values assigned to it before inserting them into the back of a container. More...
 
class  kblib::consume_iterator< F >
 An OutputIterator that simply calls a provided functor for each value assigned to it. More...
 

Namespaces

namespace  kblib
 The main namespace in which all entities from kblib are defined.
 
namespace  kblib::detail_iterators
 
namespace  kblib::detail_enumerate
 
namespace  std
 

Functions

template<typename P >
constexpr auto kblib::to_pointer (P &&p) noexcept -> auto *
 Gets a raw pointer out of any smart pointer or iterator you might pass in, without dereferencing it or relying on a get() method. More...
 
template<typename Container , typename Comp = std::less<value_type_linear_t<Container>>>
auto kblib::max_element (Container &c, Comp comp) -> value_type_linear_t< Container > *
 
template<typename C >
counting_back_insert_iterator< C > kblib::counting_back_inserter (C &c, std::size_t count=0)
 
template<typename T >
constexpr auto kblib::operator+ (T val, adjuster a) noexcept -> enable_if_t< not detail_iterators::is_addable< T, std::ptrdiff_t >::value, decltype(std::advance(val, a.adj))>
 
template<typename T >
constexpr auto kblib::operator+ (T val, incrementer) -> T
 Increments val. More...
 
template<typename T >
constexpr auto kblib::operator+ (T val, decrementer) -> T
 Decrements val. More...
 
template<typename Value , typename Delta = int>
constexpr auto kblib::range (Value min, Value max, Delta step=0) -> range_t< Value, Delta >
 Constructs a range from beginning, end, and step amount. The range is half-open, that is min is in the range but max is not. If unspecified, the step is automatically either 1 or -1, depending on whether max > min. More...
 
template<typename Value >
constexpr auto kblib::range (Value max) -> range_t< Value, incrementer >
 Constructs a half-open range [0, max). The step is automatically determined based on the sign of max. More...
 
template<typename Value , typename Delta = int>
constexpr auto kblib::irange (Value, Value, Delta=0)
 
template<typename T1 , typename T2 >
auto kblib::detail_enumerate::get_or (T1 &&t1, T2 &&t2) -> decltype(auto)
 
template<typename T >
auto kblib::detail_enumerate::get_magic_ptr () -> T *
 
template<std::size_t I, typename T >
auto kblib::get (enumeration< T > &&e) -> decltype(auto)
 
template<std::size_t I, typename T >
auto kblib::get (const enumeration< T > &&e) -> decltype(auto)
 
template<std::size_t I, typename T >
auto kblib::get (volatile enumeration< T > &e) -> decltype(auto)
 
template<std::size_t I, typename T >
auto kblib::get (const volatile enumeration< T > &e) -> decltype(auto)
 
template<typename It , typename EIt >
auto kblib::magic_enumerate (It begin, EIt end) -> enumerator_t< It, EIt >
 Allow access to indexes while using range-based for loops. More...
 
template<typename Range >
auto kblib::magic_enumerate (Range &&r) -> auto
 Allow access to indexes while using range-based for loops. Safe to use with rvalues. More...
 
template<typename Iter1 , typename Iter2 >
constexpr auto kblib::indirect (Iter1 begin, Iter2 end) noexcept(noexcept(indirect_range< Iter1, Iter2 >{begin, end})) -> indirect_range< Iter1, Iter2 >
 Create a range from an iterator pair. Primarily useful for range-for loops. More...
 
template<typename Iter1 , typename Iter2 >
 kblib::indirect_range (Iter1, Iter2) -> indirect_range< Iter1, Iter2 >
 
template<typename Iter1 , typename Iter2 >
auto kblib::cry_enumerate (Iter1 begin, Iter2 end) -> auto
 
template<typename It , typename operation >
 kblib::transform_iterator (It, operation) -> transform_iterator< It, operation >
 
template<typename base_iterator , typename operation >
auto kblib::make_transform_iterator (base_iterator it, operation op) noexcept(noexcept(transform_iterator< base_iterator, operation >{ it, std::move(op)})) -> transform_iterator< base_iterator, operation >
 Factory function to make transform_iterators. More...
 
template<typename base_iterator , typename operation >
auto kblib::transformer (base_iterator it, operation op) noexcept(noexcept(transform_iterator< base_iterator, operation >{it, std::move(op)})) -> transform_iterator< base_iterator, operation >
 Factory function to make transform_iterators. More...
 
template<typename It , typename EndIt , typename operation >
auto kblib::transform_range (It begin, EndIt end, operation op) noexcept(noexcept(indirect(transform_iterator{begin, op}, end))) -> auto
 
template<typename InputIt1 , typename EndIt , typename InputIt2 >
auto kblib::zip (InputIt1 begin1, EndIt end1, InputIt2 begin2) noexcept(zip_iterator< InputIt1, EndIt, InputIt2 >::is_nothrow_copyable) -> zip_iterator< InputIt1, EndIt, InputIt2 >
 Iterate over two ranges in lockstep, like Python's zip. More...
 
template<typename Range1 , typename Range2 >
auto kblib::zip (Range1 &&r1, Range2 &&r2) noexcept(zip_iterator< decltype(begin(r1)), decltype(end(r1)), decltype(begin(r2))>::is_nothrow_copyable) -> zip_iterator< decltype(begin(r1)), decltype(end(r1)), decltype(begin(r2))>
 Iterate over two ranges in lockstep, like Python's zip. More...
 
template<typename F >
auto kblib::consumer (F f) -> consume_iterator< F >
 Creates a consume_iterator of deduced type F. More...
 

Detailed Description

This file provides some iterators, ranges, iterator/range adapters, and operations that can be performed on iterators or smart pointers.

Author
killerbee
Date
2019-2021

Definition in file iterators.h.