xref: /llvm-project/libcxx/test/std/ranges/range.adaptors/range.join/range.join.iterator/star.pass.cpp (revision 6a664674990094c1b5d2e717256f08cb04485899)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 
11 // constexpr decltype(auto) operator*() const;
12 
13 #include <cassert>
14 #include <ranges>
15 
16 #include "test_macros.h"
17 #include "../types.h"
18 
test()19 constexpr bool test() {
20   int buffer[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
21 
22   {
23     std::ranges::join_view jv(buffer);
24     auto iter = jv.begin();
25     for (int i = 1; i < 17; ++i) {
26       assert(*iter++ == i);
27     }
28   }
29   {
30     std::ranges::join_view jv(buffer);
31     auto iter = std::next(jv.begin(), 15);
32     assert(*iter++ == 16);
33     assert(iter == jv.end());
34   }
35   {
36     ChildView children[4] = {ChildView(buffer[0]), ChildView(buffer[1]), ChildView(buffer[2]), ChildView(buffer[3])};
37     auto jv = std::ranges::join_view(ParentView(children));
38     auto iter = jv.begin();
39     for (int i = 1; i < 17; ++i) {
40       assert(*iter == i);
41       ++iter;
42     }
43   }
44 
45   return true;
46 }
47 
main(int,char **)48 int main(int, char**) {
49   test();
50   static_assert(test());
51 
52   return 0;
53 }
54