1 // Copyright (C) 2019-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 } }
23 using std::is_nothrow_constructible_v
;
25 static_assert( is_nothrow_constructible_v
<span
<int>> );
26 static_assert( is_nothrow_constructible_v
<span
<int, 0>> );
28 static_assert( is_nothrow_constructible_v
<span
<int>, span
<int>&> );
29 static_assert( is_nothrow_constructible_v
<span
<const int>, span
<int>&> );
30 static_assert( is_nothrow_constructible_v
<span
<int>, span
<int, 1>&> );
31 static_assert( is_nothrow_constructible_v
<span
<const int>, span
<int, 1>&> );
32 static_assert( is_nothrow_constructible_v
<span
<int, 1>, span
<int, 1>&> );
33 static_assert( is_nothrow_constructible_v
<span
<const int, 1>, span
<int, 1>&> );
35 static_assert( is_nothrow_constructible_v
<span
<int>, int(&)[1]> );
36 static_assert( is_nothrow_constructible_v
<span
<int, 1>, int(&)[1]> );
37 static_assert( is_nothrow_constructible_v
<span
<int>, std::array
<int, 1>&> );
38 static_assert( is_nothrow_constructible_v
<span
<int, 1>, std::array
<int, 1>&> );
41 struct sentinel
{ int* p
; };
44 bool operator==(sentinel
<B
> s
, int* p
) noexcept
{ return s
.p
== p
; }
47 std::ptrdiff_t operator-(sentinel
<B
> s
, int* p
) noexcept(B
) { return s
.p
- p
; }
50 std::ptrdiff_t operator-(int* p
, sentinel
<B
> s
) noexcept
{ return p
- s
.p
; }
52 static_assert(std::sized_sentinel_for
<sentinel
<true>, int*>);
53 static_assert(std::sized_sentinel_for
<sentinel
<false>, int*>);
55 static_assert(is_nothrow_constructible_v
<span
<int>, int*, std::size_t>);
56 static_assert(is_nothrow_constructible_v
<span
<int>, int*, const int*>);
57 static_assert(is_nothrow_constructible_v
<span
<int>, int*, sentinel
<true>>);
58 static_assert(!is_nothrow_constructible_v
<span
<int>, int*, sentinel
<false>>);