@@ -11,13 +11,6 @@ export module containers.algorithms.keyed_binary_search;
11
11
12
12
import containers.algorithms.binary_search;
13
13
import containers.associative_container;
14
- import containers.array;
15
- import containers.begin_end;
16
- import containers.c_array;
17
- import containers.map_value_type;
18
-
19
- import bounded;
20
- import std_module;
21
14
22
15
namespace containers {
23
16
@@ -46,112 +39,3 @@ export constexpr auto keyed_equal_range(associative_range auto && map, auto && k
46
39
}
47
40
48
41
} // namespace containers
49
-
50
- using namespace bounded ::literal;
51
-
52
- struct compare_t {
53
- static constexpr auto operator ()(containers::map_value_type<int , int > const lhs, int const rhs) -> bool {
54
- return lhs.key < rhs;
55
- }
56
- static constexpr auto operator ()(int const lhs, containers::map_value_type<int , int > const rhs) -> bool {
57
- return lhs < rhs.key ;
58
- }
59
- static constexpr auto operator ()(int const lhs, int const rhs) -> bool {
60
- return lhs < rhs;
61
- }
62
- };
63
-
64
- template <auto size_>
65
- struct map_type {
66
- using key_type = int ;
67
- using mapped_type = int ;
68
-
69
- map_type () = default ;
70
- template <std::size_t size> requires (bounded::constant<size> == size_)
71
- explicit constexpr map_type(containers::c_array<containers::map_value_type<int , int >, size> && source):
72
- m_data(to_array(source))
73
- {
74
- }
75
-
76
- constexpr auto begin () const {
77
- return containers::begin (m_data);
78
- }
79
- static constexpr auto size () {
80
- return size_;
81
- }
82
- static constexpr auto compare () {
83
- return compare_t ();
84
- }
85
-
86
- containers::array<containers::map_value_type<int , int >, size_> m_data;
87
- };
88
-
89
- constexpr auto zero = map_type<0_bi>();
90
- static_assert (containers::keyed_lower_bound(zero, 0 ) == containers::end(zero));
91
- static_assert (containers::keyed_upper_bound(zero, 0 ) == containers::end(zero));
92
-
93
- constexpr auto one = map_type<1_bi>({{1 , 0 }});
94
- static_assert (containers::keyed_lower_bound(one, 0 ) == containers::begin(one));
95
- static_assert (containers::keyed_lower_bound(one, 1 ) == containers::begin(one));
96
- static_assert (containers::keyed_lower_bound(one, 2 ) == containers::end(one));
97
- static_assert (containers::keyed_upper_bound(one, 0 ) == containers::begin(one));
98
- static_assert (containers::keyed_upper_bound(one, 1 ) == containers::end(one));
99
- static_assert (containers::keyed_upper_bound(one, 2 ) == containers::end(one));
100
-
101
- constexpr auto two = map_type<2_bi>({{1 , 0 }, {2 , 0 }});
102
- static_assert (containers::keyed_lower_bound(two, 0 ) == containers::begin(two) + 0_bi);
103
- static_assert (containers::keyed_lower_bound(two, 1 ) == containers::begin(two) + 0_bi);
104
- static_assert (containers::keyed_lower_bound(two, 2 ) == containers::begin(two) + 1_bi);
105
- static_assert (containers::keyed_lower_bound(two, 3 ) == containers::end(two));
106
- static_assert (containers::keyed_upper_bound(two, 0 ) == containers::begin(two) + 0_bi);
107
- static_assert (containers::keyed_upper_bound(two, 1 ) == containers::begin(two) + 1_bi);
108
- static_assert (containers::keyed_upper_bound(two, 2 ) == containers::begin(two) + 2_bi);
109
- static_assert (containers::keyed_upper_bound(two, 3 ) == containers::end(two));
110
-
111
- constexpr auto three = map_type<3_bi>({{1 , 0 }, {2 , 0 }, {3 , 0 }});
112
- static_assert (containers::keyed_lower_bound(three, 0 ) == containers::begin(three) + 0_bi);
113
- static_assert (containers::keyed_lower_bound(three, 1 ) == containers::begin(three) + 0_bi);
114
- static_assert (containers::keyed_lower_bound(three, 2 ) == containers::begin(three) + 1_bi);
115
- static_assert (containers::keyed_lower_bound(three, 3 ) == containers::begin(three) + 2_bi);
116
- static_assert (containers::keyed_lower_bound(three, 4 ) == containers::end(three));
117
- static_assert (containers::keyed_upper_bound(three, 0 ) == containers::begin(three) + 0_bi);
118
- static_assert (containers::keyed_upper_bound(three, 1 ) == containers::begin(three) + 1_bi);
119
- static_assert (containers::keyed_upper_bound(three, 2 ) == containers::begin(three) + 2_bi);
120
- static_assert (containers::keyed_upper_bound(three, 3 ) == containers::begin(three) + 3_bi);
121
- static_assert (containers::keyed_upper_bound(three, 4 ) == containers::end(three));
122
-
123
- constexpr auto two_duplicates = map_type<2_bi>({{1 , 0 }, {1 , 0 }});
124
- static_assert (containers::keyed_lower_bound(two_duplicates, 0 ) == containers::begin(two_duplicates) + 0_bi);
125
- static_assert (containers::keyed_lower_bound(two_duplicates, 1 ) == containers::begin(two_duplicates) + 0_bi);
126
- static_assert (containers::keyed_lower_bound(two_duplicates, 2 ) == containers::end(two_duplicates));
127
- static_assert (containers::keyed_upper_bound(two_duplicates, 0 ) == containers::begin(two_duplicates) + 0_bi);
128
- static_assert (containers::keyed_upper_bound(two_duplicates, 1 ) == containers::end(two_duplicates));
129
- static_assert (containers::keyed_upper_bound(two_duplicates, 2 ) == containers::end(two_duplicates));
130
-
131
- constexpr auto three_duplicates = map_type<3_bi>({{1 , 0 }, {1 , 0 }, {1 , 0 }});
132
- static_assert (containers::keyed_lower_bound(three_duplicates, 0 ) == containers::begin(three_duplicates) + 0_bi);
133
- static_assert (containers::keyed_lower_bound(three_duplicates, 1 ) == containers::begin(three_duplicates) + 0_bi);
134
- static_assert (containers::keyed_lower_bound(three_duplicates, 2 ) == containers::end(three_duplicates));
135
- static_assert (containers::keyed_upper_bound(three_duplicates, 0 ) == containers::begin(three_duplicates) + 0_bi);
136
- static_assert (containers::keyed_upper_bound(three_duplicates, 1 ) == containers::end(three_duplicates));
137
- static_assert (containers::keyed_upper_bound(three_duplicates, 2 ) == containers::end(three_duplicates));
138
-
139
- constexpr auto three_two_duplicates_first = map_type<3_bi>({{1 , 0 }, {1 , 0 }, {2 , 0 }});
140
- static_assert (containers::keyed_lower_bound(three_two_duplicates_first, 0 ) == containers::begin(three_two_duplicates_first) + 0_bi);
141
- static_assert (containers::keyed_lower_bound(three_two_duplicates_first, 1 ) == containers::begin(three_two_duplicates_first) + 0_bi);
142
- static_assert (containers::keyed_lower_bound(three_two_duplicates_first, 2 ) == containers::begin(three_two_duplicates_first) + 2_bi);
143
- static_assert (containers::keyed_lower_bound(three_two_duplicates_first, 3 ) == containers::end(three_two_duplicates_first));
144
- static_assert (containers::keyed_upper_bound(three_two_duplicates_first, 0 ) == containers::begin(three_two_duplicates_first) + 0_bi);
145
- static_assert (containers::keyed_upper_bound(three_two_duplicates_first, 1 ) == containers::begin(three_two_duplicates_first) + 2_bi);
146
- static_assert (containers::keyed_upper_bound(three_two_duplicates_first, 2 ) == containers::begin(three_two_duplicates_first) + 3_bi);
147
- static_assert (containers::keyed_upper_bound(three_two_duplicates_first, 3 ) == containers::end(three_two_duplicates_first));
148
-
149
- constexpr auto three_two_duplicates_last = map_type<3_bi>({{1 , 0 }, {2 , 0 }, {2 , 0 }});
150
- static_assert (containers::keyed_lower_bound(three_two_duplicates_last, 0 ) == containers::begin(three_two_duplicates_last) + 0_bi);
151
- static_assert (containers::keyed_lower_bound(three_two_duplicates_last, 1 ) == containers::begin(three_two_duplicates_last) + 0_bi);
152
- static_assert (containers::keyed_lower_bound(three_two_duplicates_last, 2 ) == containers::begin(three_two_duplicates_last) + 1_bi);
153
- static_assert (containers::keyed_lower_bound(three_two_duplicates_last, 3 ) == containers::end(three_two_duplicates_last));
154
- static_assert (containers::keyed_upper_bound(three_two_duplicates_last, 0 ) == containers::begin(three_two_duplicates_last) + 0_bi);
155
- static_assert (containers::keyed_upper_bound(three_two_duplicates_last, 1 ) == containers::begin(three_two_duplicates_last) + 1_bi);
156
- static_assert (containers::keyed_upper_bound(three_two_duplicates_last, 2 ) == containers::begin(three_two_duplicates_last) + 3_bi);
157
- static_assert (containers::keyed_upper_bound(three_two_duplicates_last, 3 ) == containers::end(three_two_duplicates_last));
0 commit comments