12 std::array a = {1, 2, 3, 4, 5};
13 std::vector v = {9, 9, 9, 9, 9, 9, 9, 9};
16 SECTION(
"range to output-iterator") {
18 CHECK(v == std::vector{9, 1, 2, 3, 4, 5, 9, 9});
21 CHECK(v == std::vector{1, 2, 3, 4, 5, 5, 9, 9});
25 SECTION(
"sized_range to sized_range") {
27 CHECK(v == std::vector{9, 1, 2, 3, 4, 5, 9, 9});
30 CHECK(v == std::vector{1, 2, 3, 4, 5, 5, 9, 9});
35 SECTION(
"bw-compat") {
36 std::array<int, 10> buffer = {};
46 CHECK(
to_vector(buffer) == std::vector{1, 2, 3, 4, 5, 0, 0, 0, 0, 0});
51 std::array<int, 10> buffer2 = {};
53 CHECK(
to_vector(buffer2) == std::vector{1, 2, 3, 4, 5, 0, 0, 0, 0, 0});
59 auto always_equal = [](
const auto&,
const auto&) {
return true; };
61 SECTION(
"sized ranges") {
62 std::array a3 = {1, 2, 3};
63 std::vector v3 = {1, 2, 3};
64 std::array a4 = {2, 4, 6, 8};
65 std::vector
v4 = {1, 2, 3, 4};
90 auto mul2 = [](
const auto& e) {
return e * 2; };
91 auto div2 = [](
const auto& e) {
return e / 2; };
98 SECTION(
"non-sized ranges") {
99 std::array a2 = {2, 4};
100 std::array a3 = {1, 3, 5};
101 std::array a4 = {1, 3, 5, 7};
102 std::array a5 = {1, 2, 3, 4, 5};
103 auto is_even = [](
const auto& e) {
return (e & 1) == 0; };
104 auto is_odd = [](
const auto& e) {
return (e & 1) == 1; };
122 std::array b3 = {9, 9, 9};
131 std::array ss = {
S{9, 1},
S{9, 3},
S{9, 5}};
166 SECTION(
"no projection") {
167 std::array a = {3, 5, 9, 13, 19, 22, 45, 87, 98};
186 SECTION(
"not found") {
198 SECTION(
"no projection, reverse sorted") {
199 std::vector v = {86, 54, 33, 29, 14, 3};
205 SECTION(
"projection") {
210 std::vector v = {
S{4,
"four"},
S{6,
"six"},
S{10,
"ten"},
S{99,
"a lot"}};
224 SECTION(
"from vector") {
225 std::vector v = {2, 6, 7, 9, 1, 3, 4, 5, 6, 0, 1};
226 SECTION(
"dynamic size") {
229 CHECK(s.data() == &v[0]);
230 CHECK(s.size() == 11);
231 CHECK(s.extent == std::dynamic_extent);
233 SECTION(
"till end") {
235 CHECK(s.data() == &v[6]);
236 CHECK(s.size() == 5);
237 CHECK(s.extent == std::dynamic_extent);
239 SECTION(
"till end, empty") {
242 CHECK(s.extent == std::dynamic_extent);
244 SECTION(
"from start, with size") {
246 CHECK(s.data() == &v[0]);
247 CHECK(s.size() == 3);
248 CHECK(s.extent == std::dynamic_extent);
252 CHECK(s.data() == &v[4]);
253 CHECK(s.size() == 5);
254 CHECK(s.extent == std::dynamic_extent);
257 SECTION(
"fixed size") {
259 auto s = subspan<11>(v);
260 CHECK(s.data() == &v[0]);
261 CHECK(s.size() == 11);
262 CHECK(s.extent == 11);
264 SECTION(
"from start") {
265 auto s = subspan<5>(v);
266 CHECK(s.data() == &v[0]);
267 CHECK(s.size() == 5);
268 CHECK(s.extent == 5);
271 auto s = subspan<7>(v, 2);
272 CHECK(s.data() == &v[2]);
273 CHECK(s.size() == 7);
274 CHECK(s.extent == 7);
277 auto s = subspan<0>(v, 2);
279 CHECK(s.extent == 0);
283 SECTION(
"from array") {
284 std::array a = {3, 5, 1, 2, 3, 9, 1, 0};
287 CHECK(s1.data() == &a[2]);
288 CHECK(s1.size() == 3);
289 CHECK(s1.extent == std::dynamic_extent);
291 auto s2 = subspan<4>(a, 1);
292 CHECK(s2.data() == &a[1]);
293 CHECK(s2.size() == 4);
294 CHECK(s2.extent == 4);
296 SECTION(
"from string") {
297 std::string s =
"abcdefghijklmnopqrstuvwxyz";
300 CHECK(s1.data() == &s[20]);
301 CHECK(s1.size() == 6);
302 CHECK(s1.extent == std::dynamic_extent);
304 auto s2 = subspan<3>(s, 6);
305 CHECK(s2.data() == &s[6]);
306 CHECK(s2.size() == 3);
307 CHECK(s2.extent == 3);
309 SECTION(
"from another span") {
310 std::vector v = {2, 4, 6, 8, 4, 2};
314 CHECK(s1.data() == &v[0]);
315 CHECK(s1.size() == 3);
316 CHECK(s1.extent == std::dynamic_extent);
318 auto s2 = subspan<4>(s, 2);
319 CHECK(s2.data() == &v[2]);
320 CHECK(s2.size() == 4);
321 CHECK(s2.extent == 4);
323 SECTION(
"from a class with begin/end methods") {
325 const auto*
begin()
const {
return a.begin(); }
326 const auto*
end()
const {
return a.end(); }
327 std::array<int, 10> a;
331 CHECK(s1.data() == &s.a[4]);
332 CHECK(s1.size() == 5);
333 CHECK(s1.extent == std::dynamic_extent);
335 auto s2 = subspan<7>(s, 1);
336 CHECK(s2.data() == &s.a[1]);
337 CHECK(s2.size() == 7);
338 CHECK(s2.extent == 7);