Debian Codegraph @

libstdc++-v3/testsuite/23_containers/span/lwg3255.cc

raw
1 // Copyright (C) 2019-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do compile { target c++20 } }
19
20 #include <span>
21 #include <array>
22
23 using std::span;
24 using std::dynamic_extent;
25 using std::array;
26 using std::is_constructible_v;
27
28 // LWG 3255 span's array constructor is too strict
29
30 static_assert( is_constructible_v<span<const int* const>, array<int*, 2>> );
31 static_assert( is_constructible_v<span<const int>, array<const int, 4>> );
32
33 static_assert( is_constructible_v<span<int, 1>, int(&)[1]> );
34 static_assert( is_constructible_v<span<const int, 1>, int(&)[1]> );
35 static_assert( is_constructible_v<span<const int, 1>, const int(&)[1]> );
36
37 static_assert( is_constructible_v<span<int, 1>, array<int, 1>&> );
38 static_assert( is_constructible_v<span<const int, 1>, array<int, 1>&> );
39 static_assert( is_constructible_v<span<const int, 1>, array<const int, 1>&> );
40
41 static_assert( is_constructible_v<span<const int, 1>, const array<int, 1>&> );
42 static_assert( is_constructible_v<span<const int, 1>, const array<const int, 1>&> );
43
44 static_assert( !is_constructible_v<span<int, 1>, int(&)[2]> );
45 static_assert( !is_constructible_v<span<const int, 1>, int(&)[2]> );
46 static_assert( !is_constructible_v<span<const int, 1>, const int(&)[2]> );
47
48 static_assert( !is_constructible_v<span<int, 1>, array<int, 2>&> );
49 static_assert( !is_constructible_v<span<const int, 1>, array<int, 2>&> );
50 static_assert( !is_constructible_v<span<const int, 1>, array<const int, 2>&> );
51
52 static_assert( !is_constructible_v<span<int, 1>, const array<int, 2>&> );
53 static_assert( !is_constructible_v<span<const int, 1>, const array<int, 2>&> );
54 static_assert( !is_constructible_v<span<const int, 1>, const array<const int, 2>&> );
55
56 static_assert( is_constructible_v<span<int>, int(&)[2]> );
57 static_assert( is_constructible_v<span<const int>, int(&)[2]> );
58 static_assert( is_constructible_v<span<const int>, const int(&)[2]> );
59 static_assert( is_constructible_v<span<const int>, int[2]> );
60 static_assert( is_constructible_v<span<const int>, const int[2]> );
61
62 static_assert( is_constructible_v<span<int>, array<int, 2>&> );
63 static_assert( is_constructible_v<span<const int>, array<int, 2>&> );
64 static_assert( is_constructible_v<span<const int>, array<const int, 2>&> );
65 static_assert( is_constructible_v<span<const int>, array<int, 2>> );
66 static_assert( is_constructible_v<span<const int>, array<const int, 2>> );
67
68 static_assert( is_constructible_v<span<const int>, const array<int, 2>&> );
69 static_assert( is_constructible_v<span<const int>, const array<const int, 2>&> );
70
71 static_assert( ! is_constructible_v<span<int, 1>, array<const int, 1>&> );
72 static_assert( ! is_constructible_v<span<int, 1>, const array<int, 1>&> );
73 static_assert( ! is_constructible_v<span<int, 1>, const array<const int, 1>&> );
74 static_assert( ! is_constructible_v<span<int>, array<const int, 2>&> );
75 static_assert( ! is_constructible_v<span<int>, const array<int, 2>&> );
76 static_assert( ! is_constructible_v<span<int>, const array<const int, 2>&> );