1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <list>
10
11// class list
12
13// size_type size() const noexcept;
14
15#include <list>
16#include <cassert>
17
18#include "test_macros.h"
19#include "min_allocator.h"
20
21int main(int, char**) {
22 {
23 typedef std::list<int> C;
24 C c;
25 ASSERT_NOEXCEPT(c.size());
26 assert(c.size() == 0);
27 c.push_back(x: C::value_type(2));
28 assert(c.size() == 1);
29 c.push_back(x: C::value_type(1));
30 assert(c.size() == 2);
31 c.push_back(x: C::value_type(3));
32 assert(c.size() == 3);
33 c.erase(position: c.begin());
34 assert(c.size() == 2);
35 c.erase(position: c.begin());
36 assert(c.size() == 1);
37 c.erase(position: c.begin());
38 assert(c.size() == 0);
39 }
40#if TEST_STD_VER >= 11
41 {
42 typedef std::list<int, min_allocator<int>> C;
43 C c;
44 ASSERT_NOEXCEPT(c.size());
45 assert(c.size() == 0);
46 c.push_back(C::value_type(2));
47 assert(c.size() == 1);
48 c.push_back(C::value_type(1));
49 assert(c.size() == 2);
50 c.push_back(C::value_type(3));
51 assert(c.size() == 3);
52 c.erase(c.begin());
53 assert(c.size() == 2);
54 c.erase(c.begin());
55 assert(c.size() == 1);
56 c.erase(c.begin());
57 assert(c.size() == 0);
58 }
59#endif
60
61 return 0;
62}
63

source code of libcxx/test/std/containers/sequences/list/list.capacity/size.pass.cpp