aboutsummaryrefslogtreecommitdiff
path: root/src/util/ranges.hpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-23 17:05:43 +0200
committerHampusM <hampus@hampusmat.com>2022-06-23 18:24:48 +0200
commita570e494bca43c30d7ec91d293051c0c818509b5 (patch)
tree4eea8c16d1434893ca51b721c5498ece65c836aa /src/util/ranges.hpp
parentec5c7cbccc533bacab661e991e7011584d3bb47f (diff)
feat: add statusline mode styling
Diffstat (limited to 'src/util/ranges.hpp')
-rw-r--r--src/util/ranges.hpp47
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"