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