]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/24_iterators/container_access.cc
1 // { dg-do run { target c++17 } }
3 // Copyright (C) 2015-2022 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 24.8, container access [iterator.container]
24 #include <testsuite_hooks.h>
30 VERIFY(std::data(i
) == i
);
31 VERIFY(std::size(i
) == 42);
32 VERIFY(!std::empty(i
));
38 static constexpr int i
[42]{};
39 constexpr auto d
= std::data(i
);
40 static_assert(d
== i
);
41 constexpr auto s
= std::size(i
);
42 static_assert(s
== 42);
43 constexpr auto e
= std::empty(i
);
50 std::initializer_list
<int> il
{1,2,3};
51 VERIFY(std::data(il
) == il
.begin());
52 VERIFY(std::size(il
) == 3);
53 VERIFY(!std::empty(il
));
54 std::initializer_list
<int> il2
{};
55 VERIFY(std::size(il2
) == 0);
56 VERIFY(std::empty(il2
));
57 static constexpr std::initializer_list
<int> il3
{1,2,3};
58 constexpr auto d
= std::data(il3
);
59 static_assert(d
== il3
.begin());
60 constexpr auto s
= std::size(il3
);
61 static_assert(s
== 3);
62 constexpr auto e
= std::empty(il3
);
69 std::vector
<int> v
{1,2,3};
70 VERIFY(std::data(v
) == v
.data());
71 VERIFY(std::size(v
) == v
.size());
72 VERIFY(!std::empty(v
));
73 std::vector
<int> v2
{};
74 VERIFY(std::size(v2
) == v2
.size());
75 VERIFY(std::empty(v2
));