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

source code of libcxx/test/std/ranges/range.adaptors/range.zip/ctor.default.pass.cpp