2#ifndef LIBSBX_RANGE_HPP_
3#define LIBSBX_RANGE_HPP_
10#include <libsbx/utility/iterator.hpp>
16template<std::
integral Type>
21 auto operator*()
const -> Type {
25 auto operator->()
const ->
const Type* {
41 return _current == other._current;
52template<std::
integral Type>
72 auto operator ==(
iterator const& other)
const ->
bool {
73 return _step > 0 ? _current >= other._current : _current < other._current;
80 : _begin{begin, step},
83 auto begin() const -> iterator {
87 auto end() const -> iterator {
91 auto size() const -> std::
size_t {
92 if (*_end >= *_begin) {
94 if (_begin._step < Type{0}) {
99 if (_begin._step > Type{0}) {
103 return std::ceil(std::abs(
static_cast<std::float_t
>(*_end - *_begin) / _begin._step));
113template<std::
integral Type>
125 return {*_begin, *_end, step};
128 auto begin() const -> iterator {
132 auto end() const -> iterator {
136 auto size() const -> std::
size_t {
137 return *_end - *_begin;
147template<std::
integral Type>
150 iterator(Type current = Type{}, Type step = Type{})
167 auto operator==(
const iterator&)
const ->
bool {
178 : _begin{begin, step} { }
180 auto begin() const -> iterator {
184 auto end() const -> iterator {
194template<std::
integral Type>
200 bool operator==(
const iterator&)
const {
210 return {*_begin, step};
213 auto begin() const -> iterator {
217 auto end() const -> iterator {
227template<std::
integral T, std::
integral U>
228auto range(T begin, U end) -> range_proxy<std::common_type_t<T, U>> {
229 using common_type = std::common_type_t<T, U>;
230 return range_proxy{
static_cast<common_type
>(begin),
static_cast<common_type
>(end)};
233template <
typename Type>
234auto range(Type begin) -> infinite_range_proxy<Type> {
235 return infinite_range_proxy{begin};
238template<
typename Container>
239requires (
requires(
const Container& container){ { container.size() } -> std::integral; })
240auto indices(
const Container& container) -> range_proxy<
decltype(container.size())> {
241 return range_proxy{0, container.size()};
244template<
typename Type, std::
size_t Size>
245auto indices(Type(&)[Size]) -> range_proxy<std::size_t> {
246 return range_proxy{std::size_t{0}, Size};
249template<
typename Type>
250auto indices(std::initializer_list<Type>&& container) -> range_proxy<typename std::initializer_list<Type>::size_type> {
251 return range_proxy{std::size_t{0}, container.size()};
Definition: range.hpp:196
Definition: range.hpp:195
Definition: range.hpp:115
Definition: range.hpp:114
Definition: range.hpp:149
Definition: range.hpp:148
Definition: iterator.hpp:17