Home | History | Annotate | Download | only in multimap.cons
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <map>
     11 
     12 // class multimap
     13 
     14 // multimap(multimap&& m, const allocator_type& a);
     15 
     16 #include <map>
     17 #include <cassert>
     18 
     19 #include "../../../MoveOnly.h"
     20 #include "../../../test_compare.h"
     21 #include "test_allocator.h"
     22 #include "min_allocator.h"
     23 
     24 int main()
     25 {
     26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     27     {
     28         typedef std::pair<MoveOnly, MoveOnly> V;
     29         typedef std::pair<const MoveOnly, MoveOnly> VC;
     30         typedef test_compare<std::less<MoveOnly> > C;
     31         typedef test_allocator<VC> A;
     32         typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
     33         typedef std::move_iterator<V*> I;
     34         V a1[] =
     35         {
     36             V(1, 1),
     37             V(1, 2),
     38             V(1, 3),
     39             V(2, 1),
     40             V(2, 2),
     41             V(2, 3),
     42             V(3, 1),
     43             V(3, 2),
     44             V(3, 3)
     45         };
     46         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
     47         V a2[] =
     48         {
     49             V(1, 1),
     50             V(1, 2),
     51             V(1, 3),
     52             V(2, 1),
     53             V(2, 2),
     54             V(2, 3),
     55             V(3, 1),
     56             V(3, 2),
     57             V(3, 3)
     58         };
     59         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
     60         M m3(std::move(m1), A(7));
     61         assert(m3 == m2);
     62         assert(m3.get_allocator() == A(7));
     63         assert(m3.key_comp() == C(5));
     64         assert(m1.empty());
     65     }
     66     {
     67         typedef std::pair<MoveOnly, MoveOnly> V;
     68         typedef std::pair<const MoveOnly, MoveOnly> VC;
     69         typedef test_compare<std::less<MoveOnly> > C;
     70         typedef test_allocator<VC> A;
     71         typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
     72         typedef std::move_iterator<V*> I;
     73         V a1[] =
     74         {
     75             V(1, 1),
     76             V(1, 2),
     77             V(1, 3),
     78             V(2, 1),
     79             V(2, 2),
     80             V(2, 3),
     81             V(3, 1),
     82             V(3, 2),
     83             V(3, 3)
     84         };
     85         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
     86         V a2[] =
     87         {
     88             V(1, 1),
     89             V(1, 2),
     90             V(1, 3),
     91             V(2, 1),
     92             V(2, 2),
     93             V(2, 3),
     94             V(3, 1),
     95             V(3, 2),
     96             V(3, 3)
     97         };
     98         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
     99         M m3(std::move(m1), A(5));
    100         assert(m3 == m2);
    101         assert(m3.get_allocator() == A(5));
    102         assert(m3.key_comp() == C(5));
    103         assert(m1.empty());
    104     }
    105     {
    106         typedef std::pair<MoveOnly, MoveOnly> V;
    107         typedef std::pair<const MoveOnly, MoveOnly> VC;
    108         typedef test_compare<std::less<MoveOnly> > C;
    109         typedef other_allocator<VC> A;
    110         typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
    111         typedef std::move_iterator<V*> I;
    112         V a1[] =
    113         {
    114             V(1, 1),
    115             V(1, 2),
    116             V(1, 3),
    117             V(2, 1),
    118             V(2, 2),
    119             V(2, 3),
    120             V(3, 1),
    121             V(3, 2),
    122             V(3, 3)
    123         };
    124         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
    125         V a2[] =
    126         {
    127             V(1, 1),
    128             V(1, 2),
    129             V(1, 3),
    130             V(2, 1),
    131             V(2, 2),
    132             V(2, 3),
    133             V(3, 1),
    134             V(3, 2),
    135             V(3, 3)
    136         };
    137         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
    138         M m3(std::move(m1), A(5));
    139         assert(m3 == m2);
    140         assert(m3.get_allocator() == A(5));
    141         assert(m3.key_comp() == C(5));
    142         assert(m1.empty());
    143     }
    144 #if __cplusplus >= 201103L
    145     {
    146         typedef std::pair<MoveOnly, MoveOnly> V;
    147         typedef std::pair<const MoveOnly, MoveOnly> VC;
    148         typedef test_compare<std::less<MoveOnly> > C;
    149         typedef min_allocator<VC> A;
    150         typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
    151         typedef std::move_iterator<V*> I;
    152         V a1[] =
    153         {
    154             V(1, 1),
    155             V(1, 2),
    156             V(1, 3),
    157             V(2, 1),
    158             V(2, 2),
    159             V(2, 3),
    160             V(3, 1),
    161             V(3, 2),
    162             V(3, 3)
    163         };
    164         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());
    165         V a2[] =
    166         {
    167             V(1, 1),
    168             V(1, 2),
    169             V(1, 3),
    170             V(2, 1),
    171             V(2, 2),
    172             V(2, 3),
    173             V(3, 1),
    174             V(3, 2),
    175             V(3, 3)
    176         };
    177         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());
    178         M m3(std::move(m1), A());
    179         assert(m3 == m2);
    180         assert(m3.get_allocator() == A());
    181         assert(m3.key_comp() == C(5));
    182         assert(m1.empty());
    183     }
    184 #endif
    185 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    186 }
    187