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 // void swap(multimap& m);
     15 
     16 #include <map>
     17 #include <cassert>
     18 
     19 #include "min_allocator.h"
     20 
     21 int main()
     22 {
     23     typedef std::pair<const int, double> V;
     24     {
     25     typedef std::multimap<int, double> M;
     26     {
     27         V ar1[] =
     28         {
     29         };
     30         V ar2[] =
     31         {
     32         };
     33         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
     34         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
     35         M m1_save = m1;
     36         M m2_save = m2;
     37         m1.swap(m2);
     38         assert(m1 == m2_save);
     39         assert(m2 == m1_save);
     40     }
     41     {
     42         V ar1[] =
     43         {
     44         };
     45         V ar2[] =
     46         {
     47             V(5, 5),
     48             V(6, 6),
     49             V(7, 7),
     50             V(8, 8),
     51             V(9, 9),
     52             V(10, 10),
     53             V(11, 11),
     54             V(12, 12)
     55         };
     56         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
     57         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
     58         M m1_save = m1;
     59         M m2_save = m2;
     60         m1.swap(m2);
     61         assert(m1 == m2_save);
     62         assert(m2 == m1_save);
     63     }
     64     {
     65         V ar1[] =
     66         {
     67             V(1, 1),
     68             V(2, 2),
     69             V(3, 3),
     70             V(4, 4)
     71         };
     72         V ar2[] =
     73         {
     74         };
     75         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
     76         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
     77         M m1_save = m1;
     78         M m2_save = m2;
     79         m1.swap(m2);
     80         assert(m1 == m2_save);
     81         assert(m2 == m1_save);
     82     }
     83     {
     84         V ar1[] =
     85         {
     86             V(1, 1),
     87             V(2, 2),
     88             V(3, 3),
     89             V(4, 4)
     90         };
     91         V ar2[] =
     92         {
     93             V(5, 5),
     94             V(6, 6),
     95             V(7, 7),
     96             V(8, 8),
     97             V(9, 9),
     98             V(10, 10),
     99             V(11, 11),
    100             V(12, 12)
    101         };
    102         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    103         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    104         M m1_save = m1;
    105         M m2_save = m2;
    106         m1.swap(m2);
    107         assert(m1 == m2_save);
    108         assert(m2 == m1_save);
    109     }
    110     }
    111 #if __cplusplus >= 201103L
    112     {
    113     typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
    114     {
    115         V ar1[] =
    116         {
    117         };
    118         V ar2[] =
    119         {
    120         };
    121         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    122         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    123         M m1_save = m1;
    124         M m2_save = m2;
    125         m1.swap(m2);
    126         assert(m1 == m2_save);
    127         assert(m2 == m1_save);
    128     }
    129     {
    130         V ar1[] =
    131         {
    132         };
    133         V ar2[] =
    134         {
    135             V(5, 5),
    136             V(6, 6),
    137             V(7, 7),
    138             V(8, 8),
    139             V(9, 9),
    140             V(10, 10),
    141             V(11, 11),
    142             V(12, 12)
    143         };
    144         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    145         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    146         M m1_save = m1;
    147         M m2_save = m2;
    148         m1.swap(m2);
    149         assert(m1 == m2_save);
    150         assert(m2 == m1_save);
    151     }
    152     {
    153         V ar1[] =
    154         {
    155             V(1, 1),
    156             V(2, 2),
    157             V(3, 3),
    158             V(4, 4)
    159         };
    160         V ar2[] =
    161         {
    162         };
    163         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    164         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    165         M m1_save = m1;
    166         M m2_save = m2;
    167         m1.swap(m2);
    168         assert(m1 == m2_save);
    169         assert(m2 == m1_save);
    170     }
    171     {
    172         V ar1[] =
    173         {
    174             V(1, 1),
    175             V(2, 2),
    176             V(3, 3),
    177             V(4, 4)
    178         };
    179         V ar2[] =
    180         {
    181             V(5, 5),
    182             V(6, 6),
    183             V(7, 7),
    184             V(8, 8),
    185             V(9, 9),
    186             V(10, 10),
    187             V(11, 11),
    188             V(12, 12)
    189         };
    190         M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
    191         M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
    192         M m1_save = m1;
    193         M m2_save = m2;
    194         m1.swap(m2);
    195         assert(m1 == m2_save);
    196         assert(m2 == m1_save);
    197     }
    198     }
    199 #endif
    200 }
    201