79 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// <flat_map>12 13// class flat_map14 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 noexcept29 30template <class T>31concept NoExceptClear = requires(T t) {32 { t.clear() } noexcept;33};34 35static_assert(NoExceptClear<std::flat_map<int, int>>);36#ifndef TEST_HAS_NO_EXCEPTIONS37static_assert(38 NoExceptClear<std::flat_map<int, int, std::less<int>, ThrowOnMoveContainer<int>, ThrowOnMoveContainer<int>>>);39#endif40 41template <class KeyContainer, class ValueContainer>42constexpr 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>;46 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);53}54 55constexpr bool test() {56 test<std::vector<int>, std::vector<int>>();57 test<std::vector<int>, std::vector<double>>();58#ifndef __cpp_lib_constexpr_deque59 if (!TEST_IS_CONSTANT_EVALUATED)60#endif61 {62 test<std::deque<int>, std::vector<double>>();63 }64 test<MinSequenceContainer<int>, MinSequenceContainer<double>>();65 test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();66 test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();67 68 return true;69}70 71int main(int, char**) {72 test();73#if TEST_STD_VER >= 2674 static_assert(test());75#endif76 77 return 0;78}79