aboutsummaryrefslogtreecommitdiff
path: root/src/util/ranges.hpp
blob: c47c7b568c8638fe1ba6fcaf5fc249869c2baecc (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
#pragma once

#include <concepts>
#include <iterator>

template <std::weakly_incrementable Value>
class IotaViewIterator
{
public:
	constexpr explicit IotaViewIterator(Value value) noexcept;

	constexpr auto operator++() noexcept -> const IotaViewIterator &;
	constexpr auto operator++(int) noexcept -> IotaViewIterator;

	constexpr auto operator*() const noexcept -> Value;

	constexpr auto operator==(const IotaViewIterator &rhs) const noexcept -> bool;
	constexpr auto operator!=(const IotaViewIterator &rhs) const noexcept -> bool;

private:
	Value _value;
};

/**
 * A range factory that generates a sequence of elements by repeatedly incrementing an
 * initial value.
 *
 * This class was created because C++20 ranges is a complete shitshow in Clang.
 * https://github.com/llvm/llvm-project/issues/52696
 */
template <std::weakly_incrementable Value, std::semiregular Bound>
requires std::equality_comparable_with<Value, Bound> && std::copyable<Value>
class IotaView
{
public:
	constexpr IotaView(Value value, Bound bound) noexcept;

	[[nodiscard]] constexpr auto begin() const noexcept -> IotaViewIterator<Value>;

	[[nodiscard]] constexpr auto end() const noexcept -> IotaViewIterator<Value>;

private:
	Value _value;
	Bound _bound;
};

#include "ranges_impl.hpp"