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 // UNSUPPORTED: libcpp-has-no-incomplete-ranges 11 12 // Some basic examples of how zip_view might be used in the wild. This is a general 13 // collection of sample algorithms and functions that try to mock general usage of 14 // this view. 15 16 #include <ranges> 17 18 #include <array> 19 #include <cassert> 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