brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 088a883 Raw
83 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_set>12 13// class flat_multiset14 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 noexcept29 30template <class T>31concept NoExceptClear = requires(T t) {32  { t.clear() } noexcept;33};34 35static_assert(NoExceptClear<std::flat_multiset<int>>);36#ifndef TEST_HAS_NO_EXCEPTIONS37static_assert(NoExceptClear<std::flat_multiset<int, std::less<int>, ThrowOnMoveContainer<int>>>);38#endif39 40template <class KeyContainer>41constexpr 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 empty54    M m;55    assert(m.size() == 0);56    m.clear();57    assert(m.size() == 0);58  }59}60 61constexpr bool test() {62  test_one<std::vector<int>>();63  test_one<std::vector<int>>();64#ifndef __cpp_lib_constexpr_deque65  if (!TEST_IS_CONSTANT_EVALUATED)66#endif67    test_one<std::deque<int>>();68  test_one<MinSequenceContainer<int>>();69  test_one<std::vector<int, min_allocator<int>>>();70  test_one<std::vector<int, min_allocator<int>>>();71 72  return true;73}74 75int main(int, char**) {76  test();77#if TEST_STD_VER >= 2678  static_assert(test());79#endif80 81  return 0;82}83