d: Merge dmd, druntime c7902293d7, phobos 03aeafd20
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / span / deduction.cc
blobdce6cedf89bd6c8f692d07d3ee61375e1b5de27b
1 // Copyright (C) 2020-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.
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.
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/>.
18 // { dg-do compile { target c++20 } }
20 #include <span>
22 template<typename T, int N, typename U>
23 constexpr bool is_static_span(const U&)
25 return std::is_same_v<std::span<T, N>, U> && N != std::dynamic_extent;
28 template<typename T, typename U>
29 constexpr bool is_dynamic_span(const U&)
31 return std::is_same_v<std::span<T>, U>;
34 struct Range
36 float* begin() const;
37 float* end() const;
40 void
41 test01()
43 const char c[] = "";
44 int i[2]{};
45 std::array<long, 3> a;
46 Range r;
48 std::span s1(c);
49 static_assert( is_static_span<const char, 1>(s1) );
51 std::span s2(i);
52 static_assert( is_static_span<int, 2>(s2) );
54 std::span s3(a);
55 static_assert( is_static_span<long, 3>(s3) );
57 std::span s4(const_cast<const std::array<long, 3>&>(a));
58 static_assert( is_static_span<const long, 3>(s4) );
60 std::span s5(std::begin(i), std::end(i));
61 static_assert( is_dynamic_span<int>(s5) );
63 std::span s6(std::cbegin(i), std::cend(i));
64 static_assert( is_dynamic_span<const int>(s6) );
66 std::span s7(r);
67 static_assert( is_dynamic_span<float>(s7) );
69 std::span s8(s1);
70 static_assert( is_static_span<const char, 1>(s8) );
72 std::span s9(s2);
73 static_assert( is_static_span<int, 2>(s9) );
75 std::span s10(const_cast<const std::span<int, 2>&>(s2));
76 static_assert( is_static_span<int, 2>(s10) );
78 std::span s11(s5);
79 static_assert( is_dynamic_span<int>(s11) );
81 std::span s12(const_cast<const std::span<int>&>(s5));
82 static_assert( is_dynamic_span<int>(s12) );