aboutsummaryrefslogtreecommitdiff
path: root/src/util/ranges_impl.hpp
blob: b18a11cd5242c4896ae46263bd08f0e48e90c048 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#include "ranges.hpp"

// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define IOTA_VIEW_ITERATOR(return_type)                                                  \
	template <std::weakly_incrementable Value>                                           \
	constexpr return_type IotaViewIterator<Value>

IOTA_VIEW_ITERATOR()::IotaViewIterator(Value value) noexcept : _value(value) {}

IOTA_VIEW_ITERATOR(auto)::operator++() noexcept -> const IotaViewIterator &
{
	++_value;

	return *this;
}

IOTA_VIEW_ITERATOR(auto)::operator++(int) noexcept -> IotaViewIterator
{
	auto copy = *this;

	++(*this);

	return copy;
}

IOTA_VIEW_ITERATOR(auto)::operator*() const noexcept -> Value
{
	return _value;
}

IOTA_VIEW_ITERATOR(auto)::operator==(const IotaViewIterator &rhs) const noexcept -> bool
{
	return _value == rhs._value;
}

IOTA_VIEW_ITERATOR(auto)::operator!=(const IotaViewIterator &rhs) const noexcept -> bool
{
	return !(*this == rhs);
}

// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define IOTA_VIEW(return_type)                                                           \
	template <std::weakly_incrementable Value, std::semiregular Bound>                   \
	requires std::equality_comparable_with<Value, Bound> && std::copyable<Value>         \
	constexpr return_type IotaView<Value, Bound>

IOTA_VIEW()::IotaView(Value value, Bound bound) noexcept : _value(value), _bound(bound) {}

IOTA_VIEW(auto)::begin() const noexcept -> IotaViewIterator<Value>
{
	return IotaViewIterator(_value);
}

IOTA_VIEW(auto)::end() const noexcept -> IotaViewIterator<Value>
{
	return IotaViewIterator(_bound);
}