]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/24_iterators/container_access.cc
2 // { dg-options "-std=gnu++17" }
4 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
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)
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]
25 #include <testsuite_hooks.h>
27 bool test
__attribute__((unused
)) = true;
33 VERIFY(std::data(i
) == i
);
34 VERIFY(std::size(i
) == 42);
35 VERIFY(!std::empty(i
));
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
);
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
);
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
));