* ipa-fnsummary.c (estimate_node_size_and_time): Be more tolerant for
[official-gcc.git] / libstdc++-v3 / testsuite / 24_iterators / container_access.cc
blobb90324582e9379576c7c053b615ada23866bb0b0
1 // { dg-do run { target c++17 } }
2 // { dg-options "-std=gnu++17" }
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.
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.
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/>.
21 // 24.8, container access [iterator.container]
23 #include <iterator>
24 #include <vector>
25 #include <testsuite_hooks.h>
27 void
28 test01()
30 int i[42];
31 VERIFY(std::data(i) == i);
32 VERIFY(std::size(i) == 42);
33 VERIFY(!std::empty(i));
36 void
37 test02()
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);
48 void
49 test03()
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);
67 void
68 test04()
70 std::vector<int> v{1,2,3};
71 VERIFY(std::data(v) == v.data());
72 VERIFY(std::size(v) == v.size());
73 VERIFY(!std::empty(v));
74 std::vector<int> v2{};
75 VERIFY(std::size(v2) == v2.size());
76 VERIFY(std::empty(v2));
79 int
80 main()
82 test01();
83 test02();
84 test03();
85 test04();