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 // zip_view() = default; 13 14 #include <ranges> 15 16 #include <cassert> 17 #include <type_traits> 18 #include <utility> 19 20 constexpr int buff[] = {1, 2, 3}; 21 22 struct DefaultConstructibleView : std::ranges::view_base { 23 constexpr DefaultConstructibleView() : begin_(buff), end_(buff + 3) {} 24 constexpr int const* begin() const { return begin_; } 25 constexpr int const* end() const { return end_; } 26 27 private: 28 int const* begin_; 29 int const* end_; 30 }; 31 32 struct NoDefaultCtrView : std::ranges::view_base { 33 NoDefaultCtrView() = delete; 34 int* begin() const; 35 int* end() const; 36 }; 37 38 // The default constructor requires all underlying views to be default constructible. 39 // It is implicitly required by the tuple's constructor. If any of the iterators are 40 // not default constructible, zip iterator's =default would be implicitly deleted. 41 static_assert(std::is_default_constructible_v<std::ranges::zip_view<DefaultConstructibleView>>); 42 static_assert( 43 std::is_default_constructible_v<std::ranges::zip_view<DefaultConstructibleView, DefaultConstructibleView>>); 44 static_assert(!std::is_default_constructible_v<std::ranges::zip_view<DefaultConstructibleView, NoDefaultCtrView>>); 45 static_assert(!std::is_default_constructible_v<std::ranges::zip_view<NoDefaultCtrView, NoDefaultCtrView>>); 46 static_assert(!std::is_default_constructible_v<std::ranges::zip_view<NoDefaultCtrView>>); 47 48 constexpr bool test() { 49 { 50 using View = std::ranges::zip_view<DefaultConstructibleView, DefaultConstructibleView>; 51 View v = View(); // the default constructor is not explicit 52 assert(v.size() == 3); 53 auto it = v.begin(); 54 using Pair = std::pair<const int&, const int&>; 55 assert(*it++ == Pair(buff[0], buff[0])); 56 assert(*it++ == Pair(buff[1], buff[1])); 57 assert(*it == Pair(buff[2], buff[2])); 58 } 59 60 return true; 61 } 62 63 int main(int, char**) { 64 test(); 65 static_assert(test()); 66 67 return 0; 68 } 69