]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/access/cdata.cc
1 // Copyright (C) 2019-2023 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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
25 static_assert(__gnu_test::is_customization_point_object(std::ranges::cdata
));
29 = requires (T
&& t
) { std::ranges::cdata(std::forward
<T
>(t
)); };
38 int* data() { return &j
; }
39 const R
* data() const noexcept
{ return nullptr; }
41 static_assert( has_cdata
<R
&> );
42 static_assert( has_cdata
<const R
&> );
45 VERIFY( std::ranges::cdata(r
) == (R
*)nullptr );
46 static_assert( noexcept(std::ranges::cdata(r
)) );
47 VERIFY( std::ranges::cdata(c
) == (R
*)nullptr );
48 static_assert( noexcept(std::ranges::cdata(c
)) );
50 // not lvalues and not borrowed ranges
51 static_assert( !has_cdata
<R
> );
52 static_assert( !has_cdata
<const R
> );
59 VERIFY( std::ranges::cdata(a
) == a
+ 0 );
61 static_assert( has_cdata
<int(&)[2]> );
62 static_assert( !has_cdata
<int(&&)[2]> );
67 static inline int i
= 0;
68 static inline long l
= 0;
70 int* data() &; // this function is not defined
71 friend long* begin(R3
&& r
); // not defined
72 friend const long* begin(const R3
& r
) { return &r
.l
; }
73 friend const short* begin(const R3
&&); // not defined
76 template<> constexpr bool std::ranges::enable_borrowed_range
<R3
> = true;
81 static_assert( has_cdata
<R3
&> );
82 static_assert( has_cdata
<R3
> ); // borrowed range
83 static_assert( has_cdata
<const R3
&> );
84 static_assert( has_cdata
<const R3
> ); // borrowed range
88 VERIFY( std::ranges::cdata(r
) == std::ranges::data(c
) );
89 VERIFY( std::ranges::cdata(std::move(r
)) == std::ranges::data(c
) );
90 VERIFY( std::ranges::cdata(std::move(c
)) == std::ranges::begin(c
) );