1 // Copyright (C) 2019-2020 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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
20 
21 #include <ranges>
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
24 
25 using std::same_as;
26 
27 void
test01()28 test01()
29 {
30   struct R
31   {
32     constexpr int empty() const & { return 0; }
33     constexpr const void* empty() const && { return this; }
34   };
35   constexpr R r;
36   static_assert( !std::ranges::empty(r) );
37   static_assert( same_as<decltype(std::ranges::empty(r)), bool> );
38   static_assert( std::ranges::empty(std::move(r)) );
39   static_assert( same_as<decltype(std::ranges::empty(std::move(r))), bool> );
40 }
41 
42 void
test02()43 test02()
44 {
45   using __gnu_test::test_range;
46   using __gnu_test::test_sized_range;
47   using __gnu_test::random_access_iterator_wrapper;
48   using __gnu_test::forward_iterator_wrapper;
49   using __gnu_test::input_iterator_wrapper;
50   using __gnu_test::output_iterator_wrapper;
51 
52   int a[] = { 0, 1 };
53   VERIFY( !std::ranges::empty(a) );
54 
55   test_range<int, random_access_iterator_wrapper> r(a);
56   VERIFY( !std::ranges::empty(r) );
57 
58   test_range<int, forward_iterator_wrapper> i(a);
59   VERIFY( !std::ranges::empty(i) );
60 
61   test_sized_range<int, random_access_iterator_wrapper> sr(a);
62   VERIFY( !std::ranges::empty(sr) );
63 
64   test_sized_range<int, input_iterator_wrapper> si(a);
65   VERIFY( !std::ranges::empty(si) );
66 
67   test_sized_range<int, output_iterator_wrapper> so(a);
68   VERIFY( !std::ranges::empty(so) );
69 }
70 
71 int
main()72 main()
73 {
74   test01();
75   test02();
76 }
77