]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/24_iterators/container_access.cc
Fix missing returns in libstdc++ testsuite
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 24_iterators / container_access.cc
1 // { dg-do run }
2 // { dg-options "-std=gnu++17" }
3
4 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // 24.8, container access [iterator.container]
22
23 #include <iterator>
24 #include <vector>
25 #include <testsuite_hooks.h>
26
27 bool test __attribute__((unused)) = true;
28
29 void
30 test01()
31 {
32 int i[42];
33 VERIFY(std::data(i) == i);
34 VERIFY(std::size(i) == 42);
35 VERIFY(!std::empty(i));
36 }
37
38 void
39 test02()
40 {
41 static constexpr int i[42]{};
42 constexpr auto d = std::data(i);
43 static_assert(d == i);
44 constexpr auto s = std::size(i);
45 static_assert(s == 42);
46 constexpr auto e = std::empty(i);
47 static_assert(!e);
48 }
49
50 void
51 test03()
52 {
53 std::initializer_list<int> il{1,2,3};
54 VERIFY(std::data(il) == il.begin());
55 VERIFY(std::size(il) == 3);
56 VERIFY(!std::empty(il));
57 std::initializer_list<int> il2{};
58 VERIFY(std::size(il2) == 0);
59 VERIFY(std::empty(il2));
60 constexpr std::initializer_list<int> il3{1,2,3};
61 constexpr auto d = std::data(il3);
62 static_assert(d == il3.begin());
63 constexpr auto s = std::size(il3);
64 static_assert(s == 3);
65 constexpr auto e = std::empty(il3);
66 static_assert(!e);
67
68 }
69
70 void
71 test04()
72 {
73 std::vector<int> v{1,2,3};
74 VERIFY(std::data(v) == v.data());
75 VERIFY(std::size(v) == v.size());
76 VERIFY(!std::empty(v));
77 std::vector<int> v2{};
78 VERIFY(std::size(v2) == v2.size());
79 VERIFY(std::empty(v2));
80 }
81
82 int
83 main()
84 {
85 test01();
86 test02();
87 test03();
88 test04();
89 }