[compiler-rt][rtsan] inotify api for Linux interception. (#124177)
[llvm-project.git] / libcxx / test / std / containers / container.adaptors / flat.map / flat.map.modifiers / clear.pass.cpp
blob30271eb55660bf3ee906d356a94fd60f84e7c824
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // <flat_map>
13 // class flat_map
15 // void clear() noexcept;
17 #include <cassert>
18 #include <deque>
19 #include <flat_map>
20 #include <functional>
21 #include <vector>
23 #include "MinSequenceContainer.h"
24 #include "../helpers.h"
25 #include "test_macros.h"
26 #include "min_allocator.h"
28 // test noexcept
30 template <class T>
31 concept NoExceptClear = requires(T t) {
32 { t.clear() } noexcept;
35 static_assert(NoExceptClear<std::flat_map<int, int>>);
36 #ifndef TEST_HAS_NO_EXCEPTIONS
37 static_assert(
38 NoExceptClear<std::flat_map<int, int, std::less<int>, ThrowOnMoveContainer<int>, ThrowOnMoveContainer<int>>>);
39 #endif
41 template <class KeyContainer, class ValueContainer>
42 void test() {
43 using Key = typename KeyContainer::value_type;
44 using Value = typename ValueContainer::value_type;
45 using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
47 M m = {{1, 2}, {2, 1}, {3, 3}, {4, 1}, {5, 0}};
48 assert(m.size() == 5);
49 ASSERT_NOEXCEPT(m.clear());
50 ASSERT_SAME_TYPE(decltype(m.clear()), void);
51 m.clear();
52 assert(m.size() == 0);
55 int main(int, char**) {
56 test<std::vector<int>, std::vector<int>>();
57 test<std::vector<int>, std::vector<double>>();
58 test<std::deque<int>, std::vector<double>>();
59 test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
60 test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
61 test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
63 return 0;