]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/24_iterators/container_access.cc
* testsuite/24_iterators/container_access.cc (test03): Make il3 static.
[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-2017 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 void
28 test01()
29 {
30 int i[42];
31 VERIFY(std::data(i) == i);
32 VERIFY(std::size(i) == 42);
33 VERIFY(!std::empty(i));
34 }
35
36 void
37 test02()
38 {
39 static constexpr int i[42]{};
40 constexpr auto d = std::data(i);
41 static_assert(d == i);
42 constexpr auto s = std::size(i);
43 static_assert(s == 42);
44 constexpr auto e = std::empty(i);
45 static_assert(!e);
46 }
47
48 void
49 test03()
50 {
51 std::initializer_list<int> il{1,2,3};
52 VERIFY(std::data(il) == il.begin());
53 VERIFY(std::size(il) == 3);
54 VERIFY(!std::empty(il));
55 std::initializer_list<int> il2{};
56 VERIFY(std::size(il2) == 0);
57 VERIFY(std::empty(il2));
58 static constexpr std::initializer_list<int> il3{1,2,3};
59 constexpr auto d = std::data(il3);
60 static_assert(d == il3.begin());
61 constexpr auto s = std::size(il3);
62 static_assert(s == 3);
63 constexpr auto e = std::empty(il3);
64 static_assert(!e);
65
66 }
67
68 void
69 test04()
70 {
71 std::vector<int> v{1,2,3};
72 VERIFY(std::data(v) == v.data());
73 VERIFY(std::size(v) == v.size());
74 VERIFY(!std::empty(v));
75 std::vector<int> v2{};
76 VERIFY(std::size(v2) == v2.size());
77 VERIFY(std::empty(v2));
78 }
79
80 int
81 main()
82 {
83 test01();
84 test02();
85 test03();
86 test04();
87 }