-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTView.hpp
32 lines (29 loc) · 935 Bytes
/
CTView.hpp
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
#pragma once
#include <concepts>
namespace CTC {
template <typename T>
concept Iterator = requires(std::remove_cvref_t<T> a, std::remove_cvref_t<T> b) {
{ a++ } -> std::same_as<std::remove_cvref_t<T>>;
{ *a };
{ a = b };
{ a == b } -> std::convertible_to<bool>;
};
template <typename T>
concept Iterable = requires(T a) {
{ a.begin() } -> std::convertible_to<decltype(a.end())>;
{ a.begin() } -> Iterator;
};
template <Iterator T>
struct View {
T begin_;
T end_;
[[nodiscard]] auto& begin() { return begin_; }
[[nodiscard]] const auto& begin() const { return begin_; }
[[nodiscard]] auto& end() { return end_; }
[[nodiscard]] const auto& end() const { return end_; }
};
template <Iterable T>
constexpr auto view_form_iterable(T& a) {
return View{a.begin(), a.end()};
}
} // namespace CTC