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 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
9 | |
10 | // <span> |
11 | |
12 | // constexpr span(const span& other) noexcept = default; |
13 | |
14 | #include <span> |
15 | #include <cassert> |
16 | #include <string> |
17 | |
18 | #include "test_macros.h" |
19 | |
20 | template <typename T> |
21 | constexpr bool doCopy(const T &rhs) |
22 | { |
23 | ASSERT_NOEXCEPT(T{rhs}); |
24 | T lhs{rhs}; |
25 | return lhs.data() == rhs.data() |
26 | && lhs.size() == rhs.size(); |
27 | } |
28 | |
29 | struct A{}; |
30 | |
31 | template <typename T> |
32 | void testCV () |
33 | { |
34 | int arr[] = {1,2,3}; |
35 | assert((doCopy(std::span<T> () ))); |
36 | assert((doCopy(std::span<T,0>() ))); |
37 | assert((doCopy(std::span<T> (&arr[0], 1)))); |
38 | assert((doCopy(std::span<T,1>(&arr[0], 1)))); |
39 | assert((doCopy(std::span<T> (&arr[0], 2)))); |
40 | assert((doCopy(std::span<T,2>(&arr[0], 2)))); |
41 | } |
42 | |
43 | |
44 | int main(int, char**) |
45 | { |
46 | constexpr int carr[] = {1,2,3}; |
47 | |
48 | static_assert(doCopy(std::span< int> ()), "" ); |
49 | static_assert(doCopy(std::span< int,0>()), "" ); |
50 | static_assert(doCopy(std::span<const int> (&carr[0], 1)), "" ); |
51 | static_assert(doCopy(std::span<const int,1>(&carr[0], 1)), "" ); |
52 | static_assert(doCopy(std::span<const int> (&carr[0], 2)), "" ); |
53 | static_assert(doCopy(std::span<const int,2>(&carr[0], 2)), "" ); |
54 | |
55 | static_assert(doCopy(std::span<long>()), "" ); |
56 | static_assert(doCopy(std::span<double>()), "" ); |
57 | static_assert(doCopy(std::span<A>()), "" ); |
58 | |
59 | std::string s; |
60 | assert(doCopy(std::span<std::string> () )); |
61 | assert(doCopy(std::span<std::string, 0>() )); |
62 | assert(doCopy(std::span<std::string> (&s, 1))); |
63 | assert(doCopy(std::span<std::string, 1>(&s, 1))); |
64 | |
65 | testCV< int>(); |
66 | testCV<const int>(); |
67 | testCV< volatile int>(); |
68 | testCV<const volatile int>(); |
69 | |
70 | return 0; |
71 | } |
72 | |