kblib 0.2.3
General utilities library for modern C++
kblib::range_t< Value, Delta > Class Template Reference

A range generator, similar to Python 3's range(). More...

#include <kblib/iterators.h>

Classes

struct  iterator
 A helper struct which acts as an iterator for the range elements, as they are generated on the fly. More...
 

Public Member Functions

constexpr range_t (Value min_, Value max_, Delta step_=1)
 2- and 3-argument constructor. Explicitly specify start, end, and optionally the step amount. More...
 
constexpr range_t (Value max_)
 1-argument constructor. Start is implicitly zero and step is 1 or -1, depending on the sign of max. More...
 
constexpr auto begin () const noexcept -> iterator
 Returns an iterator to the beginning of the range. More...
 
constexpr auto end () const noexcept -> iterator
 Return an iterator to the end of the range. More...
 
constexpr auto size () const noexcept -> std::size_t
 Returns the distance between start() and stop(). More...
 
constexpr auto empty () const noexcept -> bool
 Query whether the range will generate any elements. More...
 
template<typename Integral >
constexpr auto operator[] (Integral x) const noexcept -> decltype(begin()[x])
 
constexpr auto lesser () const noexcept(nothrow_copyable) -> Value
 
constexpr auto greater () const noexcept(nothrow_copyable) -> Value
 
template<typename Container , enable_if_t< is_linear_container_v< Container > and std::is_constructible< Container, iterator, iterator >::value > * = nullptr>
 operator Container () const noexcept(noexcept(Container(std::declval< iterator >(), std::declval< iterator >())))
 Returns a linear container whose elements are this range. More...
 
template<typename Container , enable_if_t< is_setlike_v< Container > and std::is_constructible< Container, iterator, iterator >::value > * = nullptr>
 operator Container () const noexcept(noexcept(Container(std::declval< iterator >(), std::declval< iterator >())))
 Returns a setlike container whose elements are this range. More...
 

Friends

constexpr auto begin (const range_t &r) noexcept -> iterator
 Returns an iterator to the beginning of the range. More...
 
constexpr auto end (const range_t &r) noexcept -> iterator
 Return an iterator to the end of the range. More...
 
constexpr auto size (const range_t &r) noexcept -> std::size_t
 Returns the distance between start() and stop(). More...
 
constexpr friend auto operator== (range_t l, range_t r) noexcept -> bool
 Compare l and r for equality. More...
 
constexpr friend auto operator!= (range_t l, range_t r) noexcept -> bool
 Compare l and r for inequality. More...
 

Detailed Description

template<typename Value, typename Delta>
class kblib::range_t< Value, Delta >

A range generator, similar to Python 3's range().

Generates a half-open range, [min, max).

Template Parameters
ValueThe type of elements in the range. Must support comparison (equality and relational) and subtraction, but does not strictly need to be numeric. Must be copyable. Must be value-initializable. Notably, RandomAccessIterators are valid Value types.
DeltaA type used to mutate Value values. std::declval<Value>() + std::declval<Delta>() must be a valid expression and must return type Value. Delta must be implicitly constructible and assignable from, as well as comparable to, int.

Definition at line 222 of file iterators.h.

Constructor & Destructor Documentation

◆ range_t() [1/2]

template<typename Value , typename Delta >
constexpr kblib::range_t< Value, Delta >::range_t ( Value  min_,
Value  max_,
Delta  step_ = 1 
)
inlineconstexpr

2- and 3-argument constructor. Explicitly specify start, end, and optionally the step amount.

Parameters
min_The first value in the range.
max_The end of the range.
step_The difference between values in the range.

Definition at line 240 of file iterators.h.

◆ range_t() [2/2]

template<typename Value , typename Delta >
constexpr kblib::range_t< Value, Delta >::range_t ( Value  max_)
inlineconstexpr

1-argument constructor. Start is implicitly zero and step is 1 or -1, depending on the sign of max.

Parameters
maxThe end of the range.

Definition at line 252 of file iterators.h.

Member Function Documentation

◆ begin()

template<typename Value , typename Delta >
constexpr auto kblib::range_t< Value, Delta >::begin ( ) const -> iterator
inlineconstexprnoexcept

Returns an iterator to the beginning of the range.

Definition at line 377 of file iterators.h.

◆ empty()

template<typename Value , typename Delta >
constexpr auto kblib::range_t< Value, Delta >::empty ( ) const -> bool
inlineconstexprnoexcept

Query whether the range will generate any elements.

Definition at line 413 of file iterators.h.

◆ end()

template<typename Value , typename Delta >
constexpr auto kblib::range_t< Value, Delta >::end ( ) const -> iterator
inlineconstexprnoexcept

Return an iterator to the end of the range.

Definition at line 381 of file iterators.h.

◆ greater()

template<typename Value , typename Delta >
constexpr auto kblib::range_t< Value, Delta >::greater ( ) const -> Value
inlineconstexprnoexcept

Definition at line 425 of file iterators.h.

◆ lesser()

template<typename Value , typename Delta >
constexpr auto kblib::range_t< Value, Delta >::lesser ( ) const -> Value
inlineconstexprnoexcept

Definition at line 421 of file iterators.h.

◆ operator Container() [1/2]

template<typename Value , typename Delta >
template<typename Container , enable_if_t< is_linear_container_v< Container > and std::is_constructible< Container, iterator, iterator >::value > * = nullptr>
kblib::range_t< Value, Delta >::operator Container ( ) const
inlineexplicitnoexcept

Returns a linear container whose elements are this range.

Definition at line 437 of file iterators.h.

◆ operator Container() [2/2]

template<typename Value , typename Delta >
template<typename Container , enable_if_t< is_setlike_v< Container > and std::is_constructible< Container, iterator, iterator >::value > * = nullptr>
kblib::range_t< Value, Delta >::operator Container ( ) const
inlineexplicitnoexcept

Returns a setlike container whose elements are this range.

Definition at line 451 of file iterators.h.

◆ operator[]()

template<typename Value , typename Delta >
template<typename Integral >
constexpr auto kblib::range_t< Value, Delta >::operator[] ( Integral  x) const -> decltype(begin()[x])
inlineconstexprnoexcept

Definition at line 416 of file iterators.h.

◆ size()

template<typename Value , typename Delta >
constexpr auto kblib::range_t< Value, Delta >::size ( ) const -> std::size_t
inlineconstexprnoexcept

Returns the distance between start() and stop().

Definition at line 386 of file iterators.h.

Friends And Related Function Documentation

◆ begin

template<typename Value , typename Delta >
constexpr auto begin ( const range_t< Value, Delta > &  r) -> iterator
friend

Returns an iterator to the beginning of the range.

Definition at line 393 of file iterators.h.

◆ end

template<typename Value , typename Delta >
constexpr auto end ( const range_t< Value, Delta > &  r) -> iterator
friend

Return an iterator to the end of the range.

Definition at line 399 of file iterators.h.

◆ operator!=

template<typename Value , typename Delta >
constexpr friend auto operator!= ( range_t< Value, Delta >  l,
range_t< Value, Delta >  r 
) -> bool
friend

Compare l and r for inequality.

Ranges are equal when they generate identical ranges.

Definition at line 472 of file iterators.h.

◆ operator==

template<typename Value , typename Delta >
constexpr friend auto operator== ( range_t< Value, Delta >  l,
range_t< Value, Delta >  r 
) -> bool
friend

Compare l and r for equality.

Ranges are equal when they generate identical ranges.

Definition at line 462 of file iterators.h.

◆ size

template<typename Value , typename Delta >
constexpr auto size ( const range_t< Value, Delta > &  r) -> std::size_t
friend

Returns the distance between start() and stop().

Definition at line 406 of file iterators.h.


The documentation for this class was generated from the following file: