Iros
 
Loading...
Searching...
No Matches
integral_set.h
Go to the documentation of this file.
1#pragma once
2
5#include "di/meta/algorithm.h"
6#include "di/meta/compare.h"
7#include "di/meta/language.h"
9
10namespace di::parser {
11template<concepts::Integral T>
12struct MatchOne {
13 constexpr auto operator()(concepts::ThreeWayComparableWith<T> auto const& other) const -> bool {
14 return value == other;
15 }
16
18};
19
20template<concepts::Integral T>
21struct MatchRange {
22 constexpr auto operator()(concepts::ThreeWayComparableWith<T> auto const& other) const -> bool {
23 return lower <= other && other <= upper_inclusive;
24 }
25
28};
29
30template<concepts::Integral T, size_t N>
32 constexpr auto operator()(concepts::ThreeWayComparableWith<T> auto const& other) const -> bool {
33 return container::any_of(ranges, [&](auto const& range) {
34 return range(other);
35 });
36 }
37
39};
40
41template<concepts::Integral T, size_t N>
43 constexpr auto operator()(concepts::ThreeWayComparableWith<T> auto const& other) const -> bool {
44 return !set(other);
45 }
46
48};
49
50template<concepts::Integral T>
51constexpr auto operator~(MatchOne<T> value) {
52 return InvertedIntegralSet<T, 1> { IntegralSet<T, 1> { MatchRange<T> { value.value, value.value } } };
53}
54
55template<concepts::Integral T>
56constexpr auto operator~(MatchRange<T> value) {
58}
59
60template<concepts::Integral T, size_t N>
61constexpr auto operator~(IntegralSet<T, N> value) {
62 return InvertedIntegralSet<T, N> { value };
63}
64
65template<concepts::Integral T>
66constexpr auto operator-(MatchOne<T> a, MatchOne<T> b) {
67 return MatchRange<T> { a.value, b.value };
68}
69
70template<concepts::Integral T>
71constexpr auto operator||(MatchOne<T> a, MatchOne<T> b) {
72 return MatchRange<T> { a.value, a.value } || MatchRange<T> { b.value, b.value };
73}
74
75template<concepts::Integral T>
76constexpr auto operator||(MatchOne<T> a, MatchRange<T> b) {
77 return MatchRange<T> { a.value, a.value } || b;
78}
79
80template<concepts::Integral T>
81constexpr auto operator||(MatchRange<T> a, MatchOne<T> b) {
82 return a || MatchRange<T> { b.value, b.value };
83}
84
85template<concepts::Integral T>
87 return IntegralSet<T, 1> { a } || IntegralSet<T, 1> { b };
88}
89
90template<concepts::Integral T, size_t N>
92 return a || MatchRange<T> { b.value, b.value };
93}
94
95template<concepts::Integral T, size_t N>
97 return MatchRange<T> { a.value, a.value } | b;
98}
99
100template<concepts::Integral T, size_t N>
102 return a || IntegralSet<T, 1> { b };
103}
104
105template<concepts::Integral T, size_t N>
107 return IntegralSet<T, 1> { a } || b;
108}
109
110template<concepts::Integral T, size_t N1, size_t N2>
112 return function::unpack<meta::MakeIndexSequence<N1>>([&]<size_t... a_indices>(meta::ListV<a_indices...>) {
113 return function::unpack<meta::MakeIndexSequence<N2>>([&]<size_t... b_indices>(meta::ListV<b_indices...>) {
117 };
118 });
119 });
120}
121}
122
123namespace di {
124inline namespace literals {
125 inline namespace integral_set_literals {
126
127#define DI_DEFINE_INTEGRAL_OP(input_kind, output_kind, name) \
128 constexpr auto operator"" name(input_kind value) { \
129 return parser::MatchOne<output_kind> { (output_kind) (value) }; \
130 }
131
132 DI_DEFINE_INTEGRAL_OP(char, char, _mc)
133 DI_DEFINE_INTEGRAL_OP(char, c32, _m)
135 DI_DEFINE_INTEGRAL_OP(unsigned long long, unsigned long long, _mu)
136
137#undef DI_DEFINE_INTEGRAL_OP
138 }
139}
140}
141
142#if !defined(DI_NO_GLOBALS) && !defined(DI_NO_GLOBAL_INTEGRAL_SET_LITERALS)
144#endif
#define DI_DEFINE_INTEGRAL_OP(input_kind, output_kind, name)
Definition integral_set.h:127
constexpr auto any_of
Definition any_of.h:24
constexpr auto unpack
Definition unpack.h:24
Definition integral_set.h:125
Definition zstring_parser.h:9
constexpr auto operator||(MatchOne< T > a, MatchOne< T > b)
Definition integral_set.h:71
constexpr auto operator~(Parser &&parser)
Definition ignore.h:21
constexpr auto operator-(Parser &&parser)
Definition optional.h:45
char32_t c32
Definition char.h:6
constexpr auto get(T &&value) -> decltype(auto)
Definition get.h:8
Definition zstring_parser.h:9
Definition core.h:8
Definition integral_set.h:31
constexpr auto operator()(concepts::ThreeWayComparableWith< T > auto const &other) const -> bool
Definition integral_set.h:32
Array< MatchRange< T >, N > ranges
Definition integral_set.h:38
Definition integral_set.h:42
constexpr auto operator()(concepts::ThreeWayComparableWith< T > auto const &other) const -> bool
Definition integral_set.h:43
IntegralSet< T, N > set
Definition integral_set.h:47
Definition integral_set.h:12
constexpr auto operator()(concepts::ThreeWayComparableWith< T > auto const &other) const -> bool
Definition integral_set.h:13
T value
Definition integral_set.h:17
Definition integral_set.h:21
T lower
Definition integral_set.h:26
T upper_inclusive
Definition integral_set.h:27
constexpr auto operator()(concepts::ThreeWayComparableWith< T > auto const &other) const -> bool
Definition integral_set.h:22
Definition span_fixed_size.h:37