]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/span/deduction.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / span / deduction.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
389cd88c
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
18// { dg-options "-std=gnu++2a" }
19// { dg-do compile { target c++2a } }
20
21#include <span>
22
23template<typename T, int N, typename U>
24constexpr bool is_static_span(const U&)
25{
26 return std::is_same_v<std::span<T, N>, U> && N != std::dynamic_extent;
27}
28
29template<typename T, typename U>
30constexpr bool is_dynamic_span(const U&)
31{
32 return std::is_same_v<std::span<T>, U>;
33}
34
35struct Range
36{
37 float* begin() const;
38 float* end() const;
39};
40
41void
42test01()
43{
44 const char c[] = "";
45 int i[2]{};
46 std::array<long, 3> a;
47 Range r;
48
49 std::span s1(c);
50 static_assert( is_static_span<const char, 1>(s1) );
51
52 std::span s2(i);
53 static_assert( is_static_span<int, 2>(s2) );
54
55 std::span s3(a);
56 static_assert( is_static_span<long, 3>(s3) );
57
58 std::span s4(const_cast<const std::array<long, 3>&>(a));
59 static_assert( is_static_span<const long, 3>(s4) );
60
61 std::span s5(std::begin(i), std::end(i));
62 static_assert( is_dynamic_span<int>(s5) );
63
64 std::span s6(std::cbegin(i), std::cend(i));
65 static_assert( is_dynamic_span<const int>(s6) );
66
67 std::span s7(r);
68 static_assert( is_dynamic_span<float>(s7) );
69
70 std::span s8(s1);
71 static_assert( is_static_span<const char, 1>(s8) );
72
73 std::span s9(s2);
74 static_assert( is_static_span<int, 2>(s9) );
75
66ae31eb 76 std::span s10(const_cast<const std::span<int, 2>&>(s2));
389cd88c
JW
77 static_assert( is_static_span<int, 2>(s10) );
78
79 std::span s11(s5);
80 static_assert( is_dynamic_span<int>(s11) );
81
82 std::span s12(const_cast<const std::span<int>&>(s5));
83 static_assert( is_dynamic_span<int>(s12) );
84}