Home | History | Annotate | Download | only in map.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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <map>
     13 
     14 // class map
     15 
     16 // map(map&& m, const allocator_type& a);
     17 
     18 #include <map>
     19 #include <cassert>
     20 
     21 #include "MoveOnly.h"
     22 #include "../../../test_compare.h"
     23 #include "test_allocator.h"
     24 #include "min_allocator.h"
     25 #include "Counter.h"
     26 
     27 int main()
     28 {
     29     {
     30         typedef std::pair<MoveOnly, MoveOnly> V;
     31         typedef std::pair<const MoveOnly, MoveOnly> VC;
     32         typedef test_compare<std::less<MoveOnly> > C;
     33         typedef test_allocator<VC> A;
     34         typedef std::map<MoveOnly, MoveOnly, C, A> M;
     35         typedef std::move_iterator<V*> I;
     36         V a1[] =
     37         {
     38             V(1, 1),
     39             V(1, 2),
     40             V(1, 3),
     41             V(2, 1),
     42             V(2, 2),
     43             V(2, 3),
     44             V(3, 1),
     45             V(3, 2),
     46             V(3, 3)
     47         };
     48         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
     49         V a2[] =
     50         {
     51             V(1, 1),
     52             V(1, 2),
     53             V(1, 3),
     54             V(2, 1),
     55             V(2, 2),
     56             V(2, 3),
     57             V(3, 1),
     58             V(3, 2),
     59             V(3, 3)
     60         };
     61         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
     62         M m3(std::move(m1), A(7));
     63         assert(m3 == m2);
     64         assert(m3.get_allocator() == A(7));
     65         assert(m3.key_comp() == C(5));
     66         assert(m1.empty());
     67     }
     68     {
     69         typedef std::pair<MoveOnly, MoveOnly> V;
     70         typedef std::pair<const MoveOnly, MoveOnly> VC;
     71         typedef test_compare<std::less<MoveOnly> > C;
     72         typedef test_allocator<VC> A;
     73         typedef std::map<MoveOnly, MoveOnly, C, A> M;
     74         typedef std::move_iterator<V*> I;
     75         V a1[] =
     76         {
     77             V(1, 1),
     78             V(1, 2),
     79             V(1, 3),
     80             V(2, 1),
     81             V(2, 2),
     82             V(2, 3),
     83             V(3, 1),
     84             V(3, 2),
     85             V(3, 3)
     86         };
     87         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
     88         V a2[] =
     89         {
     90             V(1, 1),
     91             V(1, 2),
     92             V(1, 3),
     93             V(2, 1),
     94             V(2, 2),
     95             V(2, 3),
     96             V(3, 1),
     97             V(3, 2),
     98             V(3, 3)
     99         };
    100         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
    101         M m3(std::move(m1), A(5));
    102         assert(m3 == m2);
    103         assert(m3.get_allocator() == A(5));
    104         assert(m3.key_comp() == C(5));
    105         assert(m1.empty());
    106     }
    107     {
    108         typedef std::pair<MoveOnly, MoveOnly> V;
    109         typedef std::pair<const MoveOnly, MoveOnly> VC;
    110         typedef test_compare<std::less<MoveOnly> > C;
    111         typedef other_allocator<VC> A;
    112         typedef std::map<MoveOnly, MoveOnly, C, A> M;
    113         typedef std::move_iterator<V*> I;
    114         V a1[] =
    115         {
    116             V(1, 1),
    117             V(1, 2),
    118             V(1, 3),
    119             V(2, 1),
    120             V(2, 2),
    121             V(2, 3),
    122             V(3, 1),
    123             V(3, 2),
    124             V(3, 3)
    125         };
    126         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
    127         V a2[] =
    128         {
    129             V(1, 1),
    130             V(1, 2),
    131             V(1, 3),
    132             V(2, 1),
    133             V(2, 2),
    134             V(2, 3),
    135             V(3, 1),
    136             V(3, 2),
    137             V(3, 3)
    138         };
    139         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
    140         M m3(std::move(m1), A(5));
    141         assert(m3 == m2);
    142         assert(m3.get_allocator() == A(5));
    143         assert(m3.key_comp() == C(5));
    144         assert(m1.empty());
    145     }
    146     {
    147         typedef Counter<int> T;
    148         typedef std::pair<int, T> V;
    149         typedef std::pair<const int, T> VC;
    150         typedef test_allocator<VC> A;
    151         typedef std::less<int> C;
    152         typedef std::map<const int, T, C, A> M;
    153         typedef V* I;
    154         Counter_base::gConstructed = 0;
    155         {
    156             V a1[] =
    157             {
    158                 V(1, 1),
    159                 V(1, 2),
    160                 V(1, 3),
    161                 V(2, 1),
    162                 V(2, 2),
    163                 V(2, 3),
    164                 V(3, 1),
    165                 V(3, 2),
    166                 V(3, 3)
    167             };
    168             const size_t num = sizeof(a1)/sizeof(a1[0]);
    169             assert(Counter_base::gConstructed == num);
    170 
    171             M m1(I(a1), I(a1+num), C(), A());
    172             assert(Counter_base::gConstructed == num+3);
    173 
    174             M m2(m1);
    175             assert(m2 == m1);
    176             assert(Counter_base::gConstructed == num+6);
    177 
    178             M m3(std::move(m1), A());
    179             assert(m3 == m2);
    180             assert(m1.empty());
    181             assert(Counter_base::gConstructed == num+6);
    182 
    183             {
    184             M m4(std::move(m2), A(5));
    185             assert(Counter_base::gConstructed == num+6);
    186             assert(m4 == m3);
    187             assert(m2.empty());
    188             }
    189             assert(Counter_base::gConstructed == num+3);
    190         }
    191         assert(Counter_base::gConstructed == 0);
    192     }
    193     {
    194         typedef std::pair<MoveOnly, MoveOnly> V;
    195         typedef std::pair<const MoveOnly, MoveOnly> VC;
    196         typedef test_compare<std::less<MoveOnly> > C;
    197         typedef min_allocator<VC> A;
    198         typedef std::map<MoveOnly, MoveOnly, C, A> M;
    199         typedef std::move_iterator<V*> I;
    200         V a1[] =
    201         {
    202             V(1, 1),
    203             V(1, 2),
    204             V(1, 3),
    205             V(2, 1),
    206             V(2, 2),
    207             V(2, 3),
    208             V(3, 1),
    209             V(3, 2),
    210             V(3, 3)
    211         };
    212         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());
    213         V a2[] =
    214         {
    215             V(1, 1),
    216             V(1, 2),
    217             V(1, 3),
    218             V(2, 1),
    219             V(2, 2),
    220             V(2, 3),
    221             V(3, 1),
    222             V(3, 2),
    223             V(3, 3)
    224         };
    225         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());
    226         M m3(std::move(m1), A());
    227         assert(m3 == m2);
    228         assert(m3.get_allocator() == A());
    229         assert(m3.key_comp() == C(5));
    230         assert(m1.empty());
    231     }
    232     {
    233         typedef std::pair<MoveOnly, MoveOnly> V;
    234         typedef std::pair<const MoveOnly, MoveOnly> VC;
    235         typedef test_compare<std::less<MoveOnly> > C;
    236         typedef explicit_allocator<VC> A;
    237         typedef std::map<MoveOnly, MoveOnly, C, A> M;
    238         typedef std::move_iterator<V*> I;
    239         V a1[] =
    240         {
    241             V(1, 1),
    242             V(1, 2),
    243             V(1, 3),
    244             V(2, 1),
    245             V(2, 2),
    246             V(2, 3),
    247             V(3, 1),
    248             V(3, 2),
    249             V(3, 3)
    250         };
    251         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A{});
    252         V a2[] =
    253         {
    254             V(1, 1),
    255             V(1, 2),
    256             V(1, 3),
    257             V(2, 1),
    258             V(2, 2),
    259             V(2, 3),
    260             V(3, 1),
    261             V(3, 2),
    262             V(3, 3)
    263         };
    264         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A{});
    265         M m3(std::move(m1), A{});
    266         assert(m3 == m2);
    267         assert(m3.get_allocator() == A{});
    268         assert(m3.key_comp() == C(5));
    269         assert(m1.empty());
    270     }
    271 }
    272