| 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_map> |
| 12 | |
| 13 | // class flat_multimap |
| 14 | |
| 15 | // void clear() noexcept; |
| 16 | |
| 17 | #include <cassert> |
| 18 | #include <deque> |
| 19 | #include <flat_map> |
| 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_multimap<int, int>>); |
| 36 | #ifndef TEST_HAS_NO_EXCEPTIONS |
| 37 | static_assert( |
| 38 | NoExceptClear<std::flat_multimap<int, int, std::less<int>, ThrowOnMoveContainer<int>, ThrowOnMoveContainer<int>>>); |
| 39 | #endif |
| 40 | |
| 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_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>; |
| 46 | |
| 47 | M m = {{5, 2}, {2, 1}, {2, 3}, {2, 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); |
| 53 | } |
| 54 | |
| 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>>>(); |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |