brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 1f095ed Raw
94 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// flat_multiset(flat_multiset&&, const allocator_type&);14 15#include <algorithm>16#include <deque>17#include <flat_set>18#include <functional>19#include <ranges>20#include <vector>21 22#include "../helpers.h"23#include "test_macros.h"24#include "../../../test_compare.h"25#include "test_allocator.h"26 27template <template <class...> class KeyContainer>28constexpr void test() {29  {30    // The constructors in this subclause shall not participate in overload31    // resolution unless uses_allocator_v<container_type, Alloc> is true.32 33    using C  = test_less<int>;34    using A1 = test_allocator<int>;35    using A2 = other_allocator<int>;36    using V1 = KeyContainer<int, A1>;37    using V2 = KeyContainer<int, A2>;38    using M1 = std::flat_multiset<int, C, V1>;39    using M2 = std::flat_multiset<int, C, V2>;40    static_assert(std::is_constructible_v<M1, M1&&, const A1&>);41    static_assert(std::is_constructible_v<M2, M2&&, const A2&>);42    static_assert(!std::is_constructible_v<M1, M1&&, const A2&>);43    static_assert(!std::is_constructible_v<M2, M2&&, const A1&>);44  }45  {46    int expected[] = {1, 1, 2, 2, 3};47    using C        = test_less<int>;48    using A        = test_allocator<int>;49    using M        = std::flat_multiset<int, C, KeyContainer<int, A>>;50    auto mo        = M(expected, expected + 5, C(5), A(7));51    auto m         = M(std::move(mo), A(3));52 53    assert(m.key_comp() == C(5));54    assert(m.size() == 5);55    auto keys = std::move(m).extract();56    assert(keys.get_allocator() == A(3));57    assert(std::ranges::equal(keys, expected));58 59    // The original flat_multiset is moved-from.60    assert(std::is_sorted(mo.begin(), mo.end(), mo.value_comp()));61    assert(mo.empty());62    assert(mo.key_comp() == C(5));63    assert(std::move(mo).extract().get_allocator() == A(7));64  }65  {66    // moved-from object maintains invariant if one of underlying container does not clear after move67    using M = std::flat_multiset<int, std::less<>, CopyOnlyVector<int>>;68    M m1    = M({1, 2, 2, 1, 3});69    M m2(std::move(m1), std::allocator<int>{});70    assert(m2.size() == 5);71    assert(std::ranges::is_sorted(m1));72    LIBCPP_ASSERT(m1.empty());73  }74}75 76constexpr bool test() {77  test<std::vector>();78#ifndef __cpp_lib_constexpr_deque79  if (!TEST_IS_CONSTANT_EVALUATED)80#endif81    test<std::deque>();82 83  return true;84}85 86int main(int, char**) {87  test();88#if TEST_STD_VER >= 2689  static_assert(test());90#endif91 92  return 0;93}94