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 // UNSUPPORTED: libcpp-no-concepts
11 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
12
13 // General tests for join_view. This file does not test anything specifically.
14
15 #include <algorithm>
16 #include <cassert>
17 #include <ranges>
18 #include <string>
19 #include <vector>
20
21 #include "test_macros.h"
22 #include "types.h"
23
24
25 template<class R, class I>
isEqual(R & r,I i)26 bool isEqual(R &r, I i) {
27 for (auto e : r)
28 if (e != *i++)
29 return false;
30 return true;
31 }
32
main(int,char **)33 int main(int, char**) {
34 {
35 int buffer[4][4] = {{1111, 2222, 3333, 4444}, {555, 666, 777, 888}, {99, 1010, 1111, 1212}, {13, 14, 15, 16}};
36 int *flattened = reinterpret_cast<int*>(buffer);
37
38 ChildView children[4] = {ChildView(buffer[0]), ChildView(buffer[1]), ChildView(buffer[2]), ChildView(buffer[3])};
39 auto jv = std::ranges::join_view(ParentView(children));
40 assert(isEqual(jv, flattened));
41 }
42
43 {
44 std::vector<std::string> vec = {"Hello", ",", " ", "World", "!"};
45 std::string check = "Hello, World!";
46 std::ranges::join_view jv(vec);
47 assert(isEqual(jv, check.begin()));
48 }
49
50 return 0;
51 }
52