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);
     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 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     26     typedef std::pair<const int, double> V;
     27     {
     28         typedef test_compare<std::less<int> > C;
     29         typedef test_allocator<V> A;
     30         std::multimap<int, double, C, A> mo(C(5), A(7));
     31         std::multimap<int, double, C, A> m = std::move(mo);
     32         assert(m.get_allocator() == A(7));
     33         assert(m.key_comp() == C(5));
     34         assert(m.size() == 0);
     35         assert(distance(m.begin(), m.end()) == 0);
     36 
     37         assert(mo.get_allocator() == A(7));
     38         assert(mo.key_comp() == C(5));
     39         assert(mo.size() == 0);
     40         assert(distance(mo.begin(), mo.end()) == 0);
     41     }
     42     {
     43         V ar[] =
     44         {
     45             V(1, 1),
     46             V(1, 1.5),
     47             V(1, 2),
     48             V(2, 1),
     49             V(2, 1.5),
     50             V(2, 2),
     51             V(3, 1),
     52             V(3, 1.5),
     53             V(3, 2),
     54         };
     55         typedef test_compare<std::less<int> > C;
     56         typedef test_allocator<V> A;
     57         std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
     58         std::multimap<int, double, C, A> m = std::move(mo);
     59         assert(m.get_allocator() == A(7));
     60         assert(m.key_comp() == C(5));
     61         assert(m.size() == 9);
     62         assert(distance(m.begin(), m.end()) == 9);
     63         assert(*m.begin() == V(1, 1));
     64         assert(*next(m.begin()) == V(1, 1.5));
     65         assert(*next(m.begin(), 2) == V(1, 2));
     66         assert(*next(m.begin(), 3) == V(2, 1));
     67         assert(*next(m.begin(), 4) == V(2, 1.5));
     68         assert(*next(m.begin(), 5) == V(2, 2));
     69         assert(*next(m.begin(), 6) == V(3, 1));
     70         assert(*next(m.begin(), 7) == V(3, 1.5));
     71         assert(*next(m.begin(), 8) == V(3, 2));
     72 
     73         assert(mo.get_allocator() == A(7));
     74         assert(mo.key_comp() == C(5));
     75         assert(mo.size() == 0);
     76         assert(distance(mo.begin(), mo.end()) == 0);
     77     }
     78 #if __cplusplus >= 201103L
     79     {
     80         typedef test_compare<std::less<int> > C;
     81         typedef min_allocator<V> A;
     82         std::multimap<int, double, C, A> mo(C(5), A());
     83         std::multimap<int, double, C, A> m = std::move(mo);
     84         assert(m.get_allocator() == A());
     85         assert(m.key_comp() == C(5));
     86         assert(m.size() == 0);
     87         assert(distance(m.begin(), m.end()) == 0);
     88 
     89         assert(mo.get_allocator() == A());
     90         assert(mo.key_comp() == C(5));
     91         assert(mo.size() == 0);
     92         assert(distance(mo.begin(), mo.end()) == 0);
     93     }
     94     {
     95         V ar[] =
     96         {
     97             V(1, 1),
     98             V(1, 1.5),
     99             V(1, 2),
    100             V(2, 1),
    101             V(2, 1.5),
    102             V(2, 2),
    103             V(3, 1),
    104             V(3, 1.5),
    105             V(3, 2),
    106         };
    107         typedef test_compare<std::less<int> > C;
    108         typedef min_allocator<V> A;
    109         std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
    110         std::multimap<int, double, C, A> m = std::move(mo);
    111         assert(m.get_allocator() == A());
    112         assert(m.key_comp() == C(5));
    113         assert(m.size() == 9);
    114         assert(distance(m.begin(), m.end()) == 9);
    115         assert(*m.begin() == V(1, 1));
    116         assert(*next(m.begin()) == V(1, 1.5));
    117         assert(*next(m.begin(), 2) == V(1, 2));
    118         assert(*next(m.begin(), 3) == V(2, 1));
    119         assert(*next(m.begin(), 4) == V(2, 1.5));
    120         assert(*next(m.begin(), 5) == V(2, 2));
    121         assert(*next(m.begin(), 6) == V(3, 1));
    122         assert(*next(m.begin(), 7) == V(3, 1.5));
    123         assert(*next(m.begin(), 8) == V(3, 2));
    124 
    125         assert(mo.get_allocator() == A());
    126         assert(mo.key_comp() == C(5));
    127         assert(mo.size() == 0);
    128         assert(distance(mo.begin(), mo.end()) == 0);
    129     }
    130 #endif
    131 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    132 }
    133