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, c++20 |
10 | |
11 | // Some basic examples of how zip_view might be used in the wild. This is a general |
12 | // collection of sample algorithms and functions that try to mock general usage of |
13 | // this view. |
14 | |
15 | #include <ranges> |
16 | |
17 | #include <array> |
18 | #include <cassert> |
19 | #include <tuple> |
20 | #include <vector> |
21 | #include <string> |
22 | |
23 | int main(int, char**) { |
24 | { |
25 | std::ranges::zip_view v{ |
26 | std::array{1, 2}, |
27 | std::vector{4, 5, 6}, |
28 | std::array{7}, |
29 | }; |
30 | assert(std::ranges::size(v) == 1); |
31 | assert(*v.begin() == std::make_tuple(1, 4, 7)); |
32 | } |
33 | { |
34 | using namespace std::string_literals; |
35 | std::vector v{1, 2, 3, 4}; |
36 | std::array a{"abc"s , "def"s , "gh"s }; |
37 | auto view = std::views::zip(v, a); |
38 | auto it = view.begin(); |
39 | assert(&(std::get<0>(*it)) == &(v[0])); |
40 | assert(&(std::get<1>(*it)) == &(a[0])); |
41 | |
42 | ++it; |
43 | assert(&(std::get<0>(*it)) == &(v[1])); |
44 | assert(&(std::get<1>(*it)) == &(a[1])); |
45 | |
46 | ++it; |
47 | assert(&(std::get<0>(*it)) == &(v[2])); |
48 | assert(&(std::get<1>(*it)) == &(a[2])); |
49 | |
50 | ++it; |
51 | assert(it == view.end()); |
52 | } |
53 | |
54 | return 0; |
55 | } |
56 | |