1#ifndef HALCHECK_LIB_ITERATOR_IOTA_HPP
2#define HALCHECK_LIB_ITERATOR_IOTA_HPP
6#include <halcheck/lib/iterator/base.hpp>
7#include <halcheck/lib/iterator/interface.hpp>
8#include <halcheck/lib/pp.hpp>
9#include <halcheck/lib/type_traits.hpp>
14namespace halcheck {
namespace lib {
21template<
typename I,
typename =
void>
30struct iota_diff<I, lib::
enable_if_t<(std::is_integral<I>() && sizeof(lib::iter_difference_t<I>) > sizeof(I))>> {
35struct iota_diff<I, lib::
enable_if_t<std::is_integral<I>() && (sizeof(std::int8_t) > sizeof(I))>> {
40struct iota_diff<I, lib::
enable_if_t<std::is_integral<I>() && (sizeof(std::int16_t) > sizeof(I))>> {
45struct iota_diff<I, lib::
enable_if_t<std::is_integral<I>() && (sizeof(std::int32_t) > sizeof(I))>> {
50struct iota_diff<I, lib::
enable_if_t<std::is_integral<I>() && (sizeof(std::int64_t) > sizeof(I))>> {
55struct iota_diff<I, lib::
enable_if_t<std::is_integral<I>() && sizeof(I) >= sizeof(std::int64_t)>> {
147 template<typename U = T, HALCHECK_REQUIRE(std::is_unsigned<U>())>
150 _value +=
static_cast<U
>(n);
152 _value -=
static_cast<U
>(-n);
160 template<typename U = T, HALCHECK_REQUIRE(!std::is_unsigned<U>())>
184 return D(D(lhs._value) - D(rhs._value));
185 else if (rhs._value > lhs._value)
186 return D(-D(rhs._value) - D(lhs._value));
188 return D(lhs._value - rhs._value);
212template<typename T, HALCHECK_REQUIRE(std::is_integral<T>())>
213class iota_view : public lib::view_interface<iota_view<T>> {
215 iota_view() =
default;
216 iota_view(T begin, T end) : _begin(std::move(begin)), _end(std::move(end)) {}
218 iota_iterator<T> begin()
const {
return iota_iterator<T>(_begin); }
219 iota_iterator<T>
end()
const {
return iota_iterator<T>(_end); }
234 lib::iota_view<T> operator()(T begin, T end)
const {
235 return lib::iota_view<T>(std::move(begin), std::move(end));
239 lib::iota_view<T> operator()(T end)
const {
240 return lib::iota_view<T>(0, std::move(end));
constexpr iota_iterator(T value)
Constructs an iota_iterator pointing to the specified value.
Definition iota.hpp:116
friend difference_type operator-(const iota_iterator &lhs, const iota_iterator &rhs)
Determines the distance between two iterators.
Definition iota.hpp:180
iota_iterator & operator--()
Advances this iterator backwards.
Definition iota.hpp:137
friend bool operator==(const iota_iterator &lhs, const iota_iterator &rhs)
Determines if two iterators are equal.
Definition iota.hpp:173
iota_iterator & operator++()
Advances this iterator.
Definition iota.hpp:128
constexpr value_type operator*() const noexcept
Obtains the value pointed to by this iterator.
Definition iota.hpp:122
An iterator pointing to an integral value.
Definition iota.hpp:73
void pointer
This type does not support operator->.
Definition iota.hpp:95
constexpr iota_iterator()=default
Constructs a default iota_iterator.
T value_type
The type of value pointed to by this iterator.
Definition iota.hpp:85
T reference
The return type of operator*.
Definition iota.hpp:90
lib::iota_diff_t< T > difference_type
The return type of operator-.
Definition iota.hpp:100
A utility class for easily defining new iterators.
Definition interface.hpp:40
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::@23 make_iota_iterator
Constructs an iota_iterator.
typename std::iterator_traits< I >::difference_type iter_difference_t
The return type of operator- for an iterator.
Definition base.hpp:32
typename iota_diff< I >::type iota_diff_t
Computes a type large enough to contain the difference between two instances of an iterator.
Definition iota.hpp:65
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::@25 size
Obtains the size of a range.
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::end_cpo::@28 end
Gets an iterator to past the end of a range.
lib::make_unsigned_t< T > to_unsigned(T value)
Converts an integral value into its equivalent unsigned version.
Definition numeric.hpp:55
#define HALCHECK_INLINE_CONSTEXPR
A backwards-compatible substitute for inline constexpr.
Definition pp.hpp:70
typename std::enable_if< Cond, T >::type enable_if_t
An implementation of std::enable_if_t.
Definition type_traits.hpp:93
typename std::make_unsigned< T >::type make_unsigned_t
An implementation of std::make_unsigned_t.
Definition type_traits.hpp:125
Computes a type large enough to contain the difference between two instances of an iterator.
Definition iota.hpp:22