brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.6 KiB · 31ff8ff Raw
155 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++0310 11// <map>12 13// class multimap14 15// multimap(multimap&& m, const allocator_type& a);16 17#include <map>18#include <cassert>19 20#include "test_macros.h"21#include "MoveOnly.h"22#include "../../../test_compare.h"23#include "test_allocator.h"24#include "min_allocator.h"25#include "Counter.h"26 27int main(int, char**) {28  {29    typedef std::pair<MoveOnly, MoveOnly> V;30    typedef std::pair<const MoveOnly, MoveOnly> VC;31    typedef test_less<MoveOnly> C;32    typedef test_allocator<VC> A;33    typedef std::multimap<MoveOnly, MoveOnly, C, A> M;34    typedef std::move_iterator<V*> I;35    V a1[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};36    M m1(I(a1), I(a1 + sizeof(a1) / sizeof(a1[0])), C(5), A(7));37    V a2[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};38    M m2(I(a2), I(a2 + sizeof(a2) / sizeof(a2[0])), C(5), A(7));39    M m3(std::move(m1), A(7));40    assert(m3 == m2);41    assert(m3.get_allocator() == A(7));42    assert(m3.key_comp() == C(5));43    LIBCPP_ASSERT(m1.empty());44  }45  {46    typedef std::pair<MoveOnly, MoveOnly> V;47    typedef std::pair<const MoveOnly, MoveOnly> VC;48    typedef test_less<MoveOnly> C;49    typedef test_allocator<VC> A;50    typedef std::multimap<MoveOnly, MoveOnly, C, A> M;51    typedef std::move_iterator<V*> I;52    V a1[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};53    M m1(I(a1), I(a1 + sizeof(a1) / sizeof(a1[0])), C(5), A(7));54    V a2[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};55    M m2(I(a2), I(a2 + sizeof(a2) / sizeof(a2[0])), C(5), A(7));56    M m3(std::move(m1), A(5));57    assert(m3 == m2);58    assert(m3.get_allocator() == A(5));59    assert(m3.key_comp() == C(5));60    LIBCPP_ASSERT(m1.empty());61  }62  {63    typedef std::pair<MoveOnly, MoveOnly> V;64    typedef std::pair<const MoveOnly, MoveOnly> VC;65    typedef test_less<MoveOnly> C;66    typedef other_allocator<VC> A;67    typedef std::multimap<MoveOnly, MoveOnly, C, A> M;68    typedef std::move_iterator<V*> I;69    V a1[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};70    M m1(I(a1), I(a1 + sizeof(a1) / sizeof(a1[0])), C(5), A(7));71    V a2[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};72    M m2(I(a2), I(a2 + sizeof(a2) / sizeof(a2[0])), C(5), A(7));73    M m3(std::move(m1), A(5));74    assert(m3 == m2);75    assert(m3.get_allocator() == A(5));76    assert(m3.key_comp() == C(5));77    LIBCPP_ASSERT(m1.empty());78  }79  {80    typedef Counter<int> T;81    typedef std::pair<int, T> V;82    typedef std::pair<const int, T> VC;83    typedef test_allocator<VC> A;84    typedef std::less<int> C;85    typedef std::multimap<const int, T, C, A> M;86    typedef V* I;87    Counter_base::gConstructed = 0;88    {89      V a1[]                = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};90      const std::size_t num = sizeof(a1) / sizeof(a1[0]);91      assert(Counter_base::gConstructed == num);92 93      M m1(I(a1), I(a1 + num), C(), A());94      assert(Counter_base::gConstructed == 2 * num);95 96      M m2(m1);97      assert(m2 == m1);98      assert(Counter_base::gConstructed == 3 * num);99 100      M m3(std::move(m1), A());101      assert(m3 == m2);102      LIBCPP_ASSERT(m1.empty());103      assert(Counter_base::gConstructed >= (int)(3 * num));104      assert(Counter_base::gConstructed <= (int)(4 * num));105 106      {107        M m4(std::move(m2), A(5));108        assert(Counter_base::gConstructed >= (int)(3 * num));109        assert(Counter_base::gConstructed <= (int)(5 * num));110        assert(m4 == m3);111        LIBCPP_ASSERT(m2.empty());112      }113      assert(Counter_base::gConstructed >= (int)(2 * num));114      assert(Counter_base::gConstructed <= (int)(4 * num));115    }116    assert(Counter_base::gConstructed == 0);117  }118  {119    typedef std::pair<MoveOnly, MoveOnly> V;120    typedef std::pair<const MoveOnly, MoveOnly> VC;121    typedef test_less<MoveOnly> C;122    typedef min_allocator<VC> A;123    typedef std::multimap<MoveOnly, MoveOnly, C, A> M;124    typedef std::move_iterator<V*> I;125    V a1[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};126    M m1(I(a1), I(a1 + sizeof(a1) / sizeof(a1[0])), C(5), A());127    V a2[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};128    M m2(I(a2), I(a2 + sizeof(a2) / sizeof(a2[0])), C(5), A());129    M m3(std::move(m1), A());130    assert(m3 == m2);131    assert(m3.get_allocator() == A());132    assert(m3.key_comp() == C(5));133    LIBCPP_ASSERT(m1.empty());134  }135  {136    typedef std::pair<MoveOnly, MoveOnly> V;137    typedef std::pair<const MoveOnly, MoveOnly> VC;138    typedef test_less<MoveOnly> C;139    typedef explicit_allocator<VC> A;140    typedef std::multimap<MoveOnly, MoveOnly, C, A> M;141    typedef std::move_iterator<V*> I;142    V a1[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};143    M m1(I(a1), I(a1 + sizeof(a1) / sizeof(a1[0])), C(5), A{});144    V a2[] = {V(1, 1), V(1, 2), V(1, 3), V(2, 1), V(2, 2), V(2, 3), V(3, 1), V(3, 2), V(3, 3)};145    M m2(I(a2), I(a2 + sizeof(a2) / sizeof(a2[0])), C(5), A{});146    M m3(std::move(m1), A{});147    assert(m3 == m2);148    assert(m3.get_allocator() == A{});149    assert(m3.key_comp() == C(5));150    LIBCPP_ASSERT(m1.empty());151  }152 153  return 0;154}155