brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 5f30e14 Raw
76 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_multimap14 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_multimap<int, int>>);36#ifndef TEST_HAS_NO_EXCEPTIONS37static_assert(38    NoExceptClear<std::flat_multimap<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_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 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    test<std::deque<int>, std::vector<double>>();62  test<MinSequenceContainer<int>, MinSequenceContainer<double>>();63  test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();64  test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();65  return true;66}67 68int main(int, char**) {69  test();70#if TEST_STD_VER >= 2671  static_assert(test());72#endif73 74  return 0;75}76