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 // <forward_list>
10 
11 // void clear() noexcept;
12 
13 #include <forward_list>
14 #include <cassert>
15 #include <iterator>
16 
17 #include "test_macros.h"
18 #include "../../../NotConstructible.h"
19 #include "min_allocator.h"
20 
main(int,char **)21 int main(int, char**)
22 {
23     {
24         typedef NotConstructible T;
25         typedef std::forward_list<T> C;
26         C c;
27         ASSERT_NOEXCEPT(c.clear());
28         c.clear();
29         assert(std::distance(c.begin(), c.end()) == 0);
30     }
31     {
32         typedef int T;
33         typedef std::forward_list<T> C;
34         const T t[] = {0, 1, 2, 3, 4};
35         C c(std::begin(t), std::end(t));
36 
37         ASSERT_NOEXCEPT(c.clear());
38         c.clear();
39         assert(std::distance(c.begin(), c.end()) == 0);
40 
41         c.clear();
42         assert(std::distance(c.begin(), c.end()) == 0);
43     }
44 #if TEST_STD_VER >= 11
45     {
46         typedef NotConstructible T;
47         typedef std::forward_list<T, min_allocator<T>> C;
48         C c;
49         ASSERT_NOEXCEPT(c.clear());
50         c.clear();
51         assert(std::distance(c.begin(), c.end()) == 0);
52     }
53     {
54         typedef int T;
55         typedef std::forward_list<T, min_allocator<T>> C;
56         const T t[] = {0, 1, 2, 3, 4};
57         C c(std::begin(t), std::end(t));
58 
59         ASSERT_NOEXCEPT(c.clear());
60         c.clear();
61         assert(std::distance(c.begin(), c.end()) == 0);
62 
63         c.clear();
64         assert(std::distance(c.begin(), c.end()) == 0);
65     }
66 #endif
67 
68   return 0;
69 }
70