| 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 |
|
| 22 |
using std::span; |
| 23 |
using std::is_nothrow_constructible_v; |
| 24 |
|
| 25 |
static_assert( is_nothrow_constructible_v<span<int>> ); |
| 26 |
static_assert( is_nothrow_constructible_v<span<int, 0>> ); |
| 27 |
|
| 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>&> ); |
| 34 |
|
| 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>&> ); |
| 39 |
|
| 40 |
template<bool> |
| 41 |
struct sentinel { int* p; }; |
| 42 |
|
| 43 |
template<bool B> |
| 44 |
bool operator==(sentinel<B> s, int* p) noexcept { return s.p == p; } |
| 45 |
|
| 46 |
template<bool B> |
| 47 |
std::ptrdiff_t operator-(sentinel<B> s, int* p) noexcept(B) { return s.p - p; } |
| 48 |
|
| 49 |
template<bool B> |
| 50 |
std::ptrdiff_t operator-(int* p, sentinel<B> s) noexcept { return p - s.p; } |
| 51 |
|
| 52 |
static_assert(std::sized_sentinel_for<sentinel<true>, int*>); |
| 53 |
static_assert(std::sized_sentinel_for<sentinel<false>, int*>); |
| 54 |
|
| 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>>); |