diff options
Diffstat (limited to 'src/util/ranges.hpp')
-rw-r--r-- | src/util/ranges.hpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/util/ranges.hpp b/src/util/ranges.hpp new file mode 100644 index 0000000..c47c7b5 --- /dev/null +++ b/src/util/ranges.hpp @@ -0,0 +1,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" |