[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / views / span.cons / span.pass.cpp
bloba1d5c21f34da55d64510d2b12173e4c12120848c
1 // -*- C++ -*-
2 //===------------------------------ span ---------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===---------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // <span>
13 // template<class OtherElementType, size_t OtherExtent>
14 // constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
16 // Remarks: This constructor shall not participate in overload resolution unless:
17 // Extent == dynamic_extent || Extent == OtherExtent is true, and
18 // OtherElementType(*)[] is convertible to ElementType(*)[].
21 #include <span>
22 #include <cassert>
23 #include <string>
25 #include "test_macros.h"
27 void checkCV()
29 std::span< int> sp;
30 // std::span<const int> csp;
31 std::span< volatile int> vsp;
32 // std::span<const volatile int> cvsp;
34 std::span< int, 0> sp0;
35 // std::span<const int, 0> csp0;
36 std::span< volatile int, 0> vsp0;
37 // std::span<const volatile int, 0> cvsp0;
39 // dynamic -> dynamic
41 std::span<const int> s1{ sp}; // a span<const int> pointing at int.
42 std::span< volatile int> s2{ sp}; // a span< volatile int> pointing at int.
43 std::span<const volatile int> s3{ sp}; // a span<const volatile int> pointing at int.
44 std::span<const volatile int> s4{ vsp}; // a span<const volatile int> pointing at volatile int.
45 assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
48 // static -> static
50 std::span<const int, 0> s1{ sp0}; // a span<const int> pointing at int.
51 std::span< volatile int, 0> s2{ sp0}; // a span< volatile int> pointing at int.
52 std::span<const volatile int, 0> s3{ sp0}; // a span<const volatile int> pointing at int.
53 std::span<const volatile int, 0> s4{ vsp0}; // a span<const volatile int> pointing at volatile int.
54 assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
57 // static -> dynamic
59 std::span<const int> s1{ sp0}; // a span<const int> pointing at int.
60 std::span< volatile int> s2{ sp0}; // a span< volatile int> pointing at int.
61 std::span<const volatile int> s3{ sp0}; // a span<const volatile int> pointing at int.
62 std::span<const volatile int> s4{ vsp0}; // a span<const volatile int> pointing at volatile int.
63 assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
66 // dynamic -> static (not allowed)
70 template <typename T>
71 constexpr bool testConstexprSpan()
73 std::span<T> s0{};
74 std::span<T, 0> s1{};
75 std::span<T> s2(s1); // static -> dynamic
76 ASSERT_NOEXCEPT(std::span<T> {s0});
77 ASSERT_NOEXCEPT(std::span<T, 0>{s1});
78 ASSERT_NOEXCEPT(std::span<T> {s1});
80 return
81 s1.data() == nullptr && s1.size() == 0
82 && s2.data() == nullptr && s2.size() == 0;
86 template <typename T>
87 void testRuntimeSpan()
89 std::span<T> s0{};
90 std::span<T, 0> s1{};
91 std::span<T> s2(s1); // static -> dynamic
92 ASSERT_NOEXCEPT(std::span<T> {s0});
93 ASSERT_NOEXCEPT(std::span<T, 0>{s1});
94 ASSERT_NOEXCEPT(std::span<T> {s1});
96 assert(s1.data() == nullptr && s1.size() == 0);
97 assert(s2.data() == nullptr && s2.size() == 0);
101 struct A{};
103 int main(int, char**)
105 static_assert(testConstexprSpan<int>(), "");
106 static_assert(testConstexprSpan<long>(), "");
107 static_assert(testConstexprSpan<double>(), "");
108 static_assert(testConstexprSpan<A>(), "");
110 testRuntimeSpan<int>();
111 testRuntimeSpan<long>();
112 testRuntimeSpan<double>();
113 testRuntimeSpan<std::string>();
114 testRuntimeSpan<A>();
116 checkCV();
118 return 0;