brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 7ad96ed Raw
105 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// void swap(flat_multiset& y) noexcept;14 15#include <flat_set>16#include <cassert>17#include <deque>18#include <functional>19#include <vector>20 21#include "MinSequenceContainer.h"22#include "MoveOnly.h"23#include "min_allocator.h"24#include "test_macros.h"25#include "../helpers.h"26 27// test noexcept28 29template <class T>30concept NoExceptMemberSwap = requires(T t1, T t2) {31  { t1.swap(t2) } noexcept;32};33 34static_assert(NoExceptMemberSwap<std::flat_multiset<int>>);35#ifndef TEST_HAS_NO_EXCEPTIONS36static_assert(NoExceptMemberSwap<std::flat_multiset<int, std::less<int>, ThrowOnMoveContainer<int>>>);37#endif38 39template <class KeyContainer>40constexpr void test_one() {41  using Key = typename KeyContainer::value_type;42  using M   = std::flat_multiset<Key, std::less<Key>, KeyContainer>;43  {44    M m1;45    M m2;46    M m1_save = m1;47    M m2_save = m2;48    m1.swap(m2);49    assert(m1 == m2_save);50    assert(m2 == m1_save);51  }52  {53    int ar2[] = {5, 5, 7, 7, 9, 10, 11, 12};54    M m1;55    M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0]));56    M m1_save = m1;57    M m2_save = m2;58    m1.swap(m2);59    assert(m1 == m2_save);60    assert(m2 == m1_save);61  }62  {63    int ar1[] = {1, 1, 3, 4};64    M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0]));65    M m2;66    M m1_save = m1;67    M m2_save = m2;68    m1.swap(m2);69    assert(m1 == m2_save);70    assert(m2 == m1_save);71  }72  {73    int ar1[] = {1, 1, 3, 4};74    int ar2[] = {5, 5, 7, 8, 9, 10, 11, 12};75    M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0]));76    M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0]));77    M m1_save = m1;78    M m2_save = m2;79    m1.swap(m2);80    assert(m1 == m2_save);81    assert(m2 == m1_save);82  }83}84 85constexpr bool test() {86  test_one<std::vector<int>>();87#ifndef __cpp_lib_constexpr_deque88  if (!TEST_IS_CONSTANT_EVALUATED)89#endif90    test_one<std::deque<int>>();91  test_one<MinSequenceContainer<int>>();92  test_one<std::vector<int, min_allocator<int>>>();93 94  return true;95}96 97int main(int, char**) {98  test();99#if TEST_STD_VER >= 26100  static_assert(test());101#endif102 103  return 0;104}105