Home | History | Annotate | Download | only in multimap.special
      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 // template <class Key, class T, class Compare, class Allocator>
     15 //   void
     16 //   swap(multimap<Key, T, Compare, Allocator>& x, multimap<Key, T, Compare, Allocator>& y);
     17 
     18 #include <map>
     19 #include <cassert>
     20 #include "test_allocator.h"
     21 #include "../../../test_compare.h"
     22 #include "min_allocator.h"
     23 
     24 int main()
     25 {
     26     typedef std::pair<const int, double> V;
     27     {
     28     typedef std::multimap<int, double> M;
     29     {
     30         V ar1[] =
     31         {
     32         };
     33         V ar2[] =
     34         {
     35         };
     36         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
     37         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
     38         M m1_save = m1;
     39         M m2_save = m2;
     40         swap(m1, m2);
     41         assert(m1 == m2_save);
     42         assert(m2 == m1_save);
     43     }
     44     {
     45         V ar1[] =
     46         {
     47         };
     48         V ar2[] =
     49         {
     50             V(5, 5),
     51             V(6, 6),
     52             V(7, 7),
     53             V(8, 8),
     54             V(9, 9),
     55             V(10, 10),
     56             V(11, 11),
     57             V(12, 12)
     58         };
     59         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
     60         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
     61         M m1_save = m1;
     62         M m2_save = m2;
     63         swap(m1, m2);
     64         assert(m1 == m2_save);
     65         assert(m2 == m1_save);
     66     }
     67     {
     68         V ar1[] =
     69         {
     70             V(1, 1),
     71             V(2, 2),
     72             V(3, 3),
     73             V(4, 4)
     74         };
     75         V ar2[] =
     76         {
     77         };
     78         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
     79         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
     80         M m1_save = m1;
     81         M m2_save = m2;
     82         swap(m1, m2);
     83         assert(m1 == m2_save);
     84         assert(m2 == m1_save);
     85     }
     86     {
     87         V ar1[] =
     88         {
     89             V(1, 1),
     90             V(2, 2),
     91             V(3, 3),
     92             V(4, 4)
     93         };
     94         V ar2[] =
     95         {
     96             V(5, 5),
     97             V(6, 6),
     98             V(7, 7),
     99             V(8, 8),
    100             V(9, 9),
    101             V(10, 10),
    102             V(11, 11),
    103             V(12, 12)
    104         };
    105         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    106         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    107         M m1_save = m1;
    108         M m2_save = m2;
    109         swap(m1, m2);
    110         assert(m1 == m2_save);
    111         assert(m2 == m1_save);
    112     }
    113     {
    114         typedef test_allocator<V> A;
    115         typedef test_compare<std::less<int> > C;
    116         typedef std::multimap<int, double, C, A> M;
    117         V ar1[] =
    118         {
    119             V(1, 1),
    120             V(2, 2),
    121             V(3, 3),
    122             V(4, 4)
    123         };
    124         V ar2[] =
    125         {
    126             V(5, 5),
    127             V(6, 6),
    128             V(7, 7),
    129             V(8, 8),
    130             V(9, 9),
    131             V(10, 10),
    132             V(11, 11),
    133             V(12, 12)
    134         };
    135         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1));
    136         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2));
    137         M m1_save = m1;
    138         M m2_save = m2;
    139         swap(m1, m2);
    140         assert(m1 == m2_save);
    141         assert(m2 == m1_save);
    142         assert(m1.key_comp() == C(2));
    143         assert(m1.get_allocator() == A(1));
    144         assert(m2.key_comp() == C(1));
    145         assert(m2.get_allocator() == A(2));
    146     }
    147     {
    148         typedef other_allocator<V> A;
    149         typedef test_compare<std::less<int> > C;
    150         typedef std::multimap<int, double, C, A> M;
    151         V ar1[] =
    152         {
    153             V(1, 1),
    154             V(2, 2),
    155             V(3, 3),
    156             V(4, 4)
    157         };
    158         V ar2[] =
    159         {
    160             V(5, 5),
    161             V(6, 6),
    162             V(7, 7),
    163             V(8, 8),
    164             V(9, 9),
    165             V(10, 10),
    166             V(11, 11),
    167             V(12, 12)
    168         };
    169         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1));
    170         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2));
    171         M m1_save = m1;
    172         M m2_save = m2;
    173         swap(m1, m2);
    174         assert(m1 == m2_save);
    175         assert(m2 == m1_save);
    176         assert(m1.key_comp() == C(2));
    177         assert(m1.get_allocator() == A(2));
    178         assert(m2.key_comp() == C(1));
    179         assert(m2.get_allocator() == A(1));
    180     }
    181     }
    182 #if __cplusplus >= 201103L
    183     {
    184     typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
    185     {
    186         V ar1[] =
    187         {
    188         };
    189         V ar2[] =
    190         {
    191         };
    192         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    193         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    194         M m1_save = m1;
    195         M m2_save = m2;
    196         swap(m1, m2);
    197         assert(m1 == m2_save);
    198         assert(m2 == m1_save);
    199     }
    200     {
    201         V ar1[] =
    202         {
    203         };
    204         V ar2[] =
    205         {
    206             V(5, 5),
    207             V(6, 6),
    208             V(7, 7),
    209             V(8, 8),
    210             V(9, 9),
    211             V(10, 10),
    212             V(11, 11),
    213             V(12, 12)
    214         };
    215         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    216         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    217         M m1_save = m1;
    218         M m2_save = m2;
    219         swap(m1, m2);
    220         assert(m1 == m2_save);
    221         assert(m2 == m1_save);
    222     }
    223     {
    224         V ar1[] =
    225         {
    226             V(1, 1),
    227             V(2, 2),
    228             V(3, 3),
    229             V(4, 4)
    230         };
    231         V ar2[] =
    232         {
    233         };
    234         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    235         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    236         M m1_save = m1;
    237         M m2_save = m2;
    238         swap(m1, m2);
    239         assert(m1 == m2_save);
    240         assert(m2 == m1_save);
    241     }
    242     {
    243         V ar1[] =
    244         {
    245             V(1, 1),
    246             V(2, 2),
    247             V(3, 3),
    248             V(4, 4)
    249         };
    250         V ar2[] =
    251         {
    252             V(5, 5),
    253             V(6, 6),
    254             V(7, 7),
    255             V(8, 8),
    256             V(9, 9),
    257             V(10, 10),
    258             V(11, 11),
    259             V(12, 12)
    260         };
    261         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    262         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    263         M m1_save = m1;
    264         M m2_save = m2;
    265         swap(m1, m2);
    266         assert(m1 == m2_save);
    267         assert(m2 == m1_save);
    268     }
    269     {
    270         typedef min_allocator<V> A;
    271         typedef test_compare<std::less<int> > C;
    272         typedef std::multimap<int, double, C, A> M;
    273         V ar1[] =
    274         {
    275             V(1, 1),
    276             V(2, 2),
    277             V(3, 3),
    278             V(4, 4)
    279         };
    280         V ar2[] =
    281         {
    282             V(5, 5),
    283             V(6, 6),
    284             V(7, 7),
    285             V(8, 8),
    286             V(9, 9),
    287             V(10, 10),
    288             V(11, 11),
    289             V(12, 12)
    290         };
    291         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A());
    292         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A());
    293         M m1_save = m1;
    294         M m2_save = m2;
    295         swap(m1, m2);
    296         assert(m1 == m2_save);
    297         assert(m2 == m1_save);
    298         assert(m1.key_comp() == C(2));
    299         assert(m1.get_allocator() == A());
    300         assert(m2.key_comp() == C(1));
    301         assert(m2.get_allocator() == A());
    302     }
    303     }
    304 #endif
    305 }
    306