| 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 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 | |
| 11 | // <flat_set> |
| 12 | |
| 13 | // class flat_multiset |
| 14 | |
| 15 | // void clear() noexcept; |
| 16 | |
| 17 | #include <cassert> |
| 18 | #include <deque> |
| 19 | #include <flat_set> |
| 20 | #include <functional> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include "MinSequenceContainer.h" |
| 24 | #include "../helpers.h" |
| 25 | #include "test_macros.h" |
| 26 | #include "min_allocator.h" |
| 27 | |
| 28 | // test noexcept |
| 29 | |
| 30 | template <class T> |
| 31 | concept NoExceptClear = requires(T t) { |
| 32 | { t.clear() } noexcept; |
| 33 | }; |
| 34 | |
| 35 | static_assert(NoExceptClear<std::flat_multiset<int>>); |
| 36 | #ifndef TEST_HAS_NO_EXCEPTIONS |
| 37 | static_assert(NoExceptClear<std::flat_multiset<int, std::less<int>, ThrowOnMoveContainer<int>>>); |
| 38 | #endif |
| 39 | |
| 40 | template <class KeyContainer> |
| 41 | void test_one() { |
| 42 | using Key = typename KeyContainer::value_type; |
| 43 | using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>; |
| 44 | { |
| 45 | M m = {1, 1, 3, 5, 2, 3, 4, 5}; |
| 46 | assert(m.size() == 8); |
| 47 | ASSERT_NOEXCEPT(m.clear()); |
| 48 | ASSERT_SAME_TYPE(decltype(m.clear()), void); |
| 49 | m.clear(); |
| 50 | assert(m.size() == 0); |
| 51 | } |
| 52 | { |
| 53 | // was empty |
| 54 | M m; |
| 55 | assert(m.size() == 0); |
| 56 | m.clear(); |
| 57 | assert(m.size() == 0); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void test() { |
| 62 | test_one<std::vector<int>>(); |
| 63 | test_one<std::vector<int>>(); |
| 64 | test_one<std::deque<int>>(); |
| 65 | test_one<MinSequenceContainer<int>>(); |
| 66 | test_one<std::vector<int, min_allocator<int>>>(); |
| 67 | test_one<std::vector<int, min_allocator<int>>>(); |
| 68 | } |
| 69 | |
| 70 | int main(int, char**) { |
| 71 | test(); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |