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& operator=(const multimap& m);
     15 
     16 #include <map>
     17 #include <cassert>
     18 
     19 #include "../../../test_compare.h"
     20 #include "test_allocator.h"
     21 #include "min_allocator.h"
     22 
     23 int main()
     24 {
     25     {
     26         typedef std::pair<const int, double> V;
     27         V ar[] =
     28         {
     29             V(1, 1),
     30             V(1, 1.5),
     31             V(1, 2),
     32             V(2, 1),
     33             V(2, 1.5),
     34             V(2, 2),
     35             V(3, 1),
     36             V(3, 1.5),
     37             V(3, 2),
     38         };
     39         typedef test_compare<std::less<int> > C;
     40         typedef test_allocator<V> A;
     41         std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
     42         std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
     43         m = mo;
     44         assert(m == mo);
     45         assert(m.get_allocator() == A(7));
     46         assert(m.key_comp() == C(5));
     47 
     48         assert(mo.get_allocator() == A(2));
     49         assert(mo.key_comp() == C(5));
     50     }
     51     {
     52         typedef std::pair<const int, double> V;
     53         const V ar[] =
     54         {
     55             V(1, 1),
     56             V(1, 1.5),
     57             V(1, 2),
     58             V(2, 1),
     59             V(2, 1.5),
     60             V(2, 2),
     61             V(3, 1),
     62             V(3, 1.5),
     63             V(3, 2),
     64         };
     65         std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     66         std::multimap<int, double> *p = &m;
     67         m = *p;
     68         assert(m.size() == sizeof(ar)/sizeof(ar[0]));
     69         assert(std::equal(m.begin(), m.end(), ar));
     70     }
     71     {
     72         typedef std::pair<const int, double> V;
     73         V ar[] =
     74         {
     75             V(1, 1),
     76             V(1, 1.5),
     77             V(1, 2),
     78             V(2, 1),
     79             V(2, 1.5),
     80             V(2, 2),
     81             V(3, 1),
     82             V(3, 1.5),
     83             V(3, 2),
     84         };
     85         typedef test_compare<std::less<int> > C;
     86         typedef other_allocator<V> A;
     87         std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
     88         std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
     89         m = mo;
     90         assert(m == mo);
     91         assert(m.get_allocator() == A(2));
     92         assert(m.key_comp() == C(5));
     93 
     94         assert(mo.get_allocator() == A(2));
     95         assert(mo.key_comp() == C(5));
     96     }
     97 #if TEST_STD_VER >= 11
     98     {
     99         typedef std::pair<const int, double> V;
    100         V ar[] =
    101         {
    102             V(1, 1),
    103             V(1, 1.5),
    104             V(1, 2),
    105             V(2, 1),
    106             V(2, 1.5),
    107             V(2, 2),
    108             V(3, 1),
    109             V(3, 1.5),
    110             V(3, 2),
    111         };
    112         typedef test_compare<std::less<int> > C;
    113         typedef min_allocator<V> A;
    114         std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
    115         std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A());
    116         m = mo;
    117         assert(m == mo);
    118         assert(m.get_allocator() == A());
    119         assert(m.key_comp() == C(5));
    120 
    121         assert(mo.get_allocator() == A());
    122         assert(mo.key_comp() == C(5));
    123     }
    124 #endif
    125 }
    126