]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/span/nothrow_cons.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / span / nothrow_cons.cc
CommitLineData
a945c346 1// Copyright (C) 2019-2024 Free Software Foundation, Inc.
cff87282
JW
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
b9a2dce8 18// { dg-do compile { target c++20 } }
cff87282
JW
19
20#include <span>
21
22using std::span;
23using std::is_nothrow_constructible_v;
24
25static_assert( is_nothrow_constructible_v<span<int>> );
26static_assert( is_nothrow_constructible_v<span<int, 0>> );
27
28static_assert( is_nothrow_constructible_v<span<int>, span<int>&> );
29static_assert( is_nothrow_constructible_v<span<const int>, span<int>&> );
30static_assert( is_nothrow_constructible_v<span<int>, span<int, 1>&> );
31static_assert( is_nothrow_constructible_v<span<const int>, span<int, 1>&> );
32static_assert( is_nothrow_constructible_v<span<int, 1>, span<int, 1>&> );
33static_assert( is_nothrow_constructible_v<span<const int, 1>, span<int, 1>&> );
34
35static_assert( is_nothrow_constructible_v<span<int>, int(&)[1]> );
36static_assert( is_nothrow_constructible_v<span<int, 1>, int(&)[1]> );
37static_assert( is_nothrow_constructible_v<span<int>, std::array<int, 1>&> );
38static_assert( is_nothrow_constructible_v<span<int, 1>, std::array<int, 1>&> );
39
40template<bool>
41struct sentinel { int* p; };
42
43template<bool B>
44bool operator==(sentinel<B> s, int* p) noexcept { return s.p == p; }
45
46template<bool B>
47std::ptrdiff_t operator-(sentinel<B> s, int* p) noexcept(B) { return s.p - p; }
48
49template<bool B>
50std::ptrdiff_t operator-(int* p, sentinel<B> s) noexcept { return p - s.p; }
51
52static_assert(std::sized_sentinel_for<sentinel<true>, int*>);
53static_assert(std::sized_sentinel_for<sentinel<false>, int*>);
54
55static_assert(is_nothrow_constructible_v<span<int>, int*, std::size_t>);
56static_assert(is_nothrow_constructible_v<span<int>, int*, const int*>);
57static_assert(is_nothrow_constructible_v<span<int>, int*, sentinel<true>>);
58static_assert(!is_nothrow_constructible_v<span<int>, int*, sentinel<false>>);