1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
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)
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 } }
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
>;
45 std::array
<long, 3> a
;
49 static_assert( is_static_span
<const char, 1>(s1
) );
52 static_assert( is_static_span
<int, 2>(s2
) );
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
) );
67 static_assert( is_dynamic_span
<float>(s7
) );
70 static_assert( is_static_span
<const char, 1>(s8
) );
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
) );
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
) );