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 // <map>
     11 
     12 // class map
     13 
     14 // map(map&& 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::map<int, double, C, A> mo(C(5), A(7));
     31         std::map<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::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
     58         std::map<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() == 3);
     62         assert(distance(m.begin(), m.end()) == 3);
     63         assert(*m.begin() == V(1, 1));
     64         assert(*next(m.begin()) == V(2, 1));
     65         assert(*next(m.begin(), 2) == V(3, 1));
     66 
     67         assert(mo.get_allocator() == A(7));
     68         assert(mo.key_comp() == C(5));
     69         assert(mo.size() == 0);
     70         assert(distance(mo.begin(), mo.end()) == 0);
     71     }
     72 #if __cplusplus >= 201103L
     73     {
     74         typedef test_compare<std::less<int> > C;
     75         typedef min_allocator<V> A;
     76         std::map<int, double, C, A> mo(C(5), A());
     77         std::map<int, double, C, A> m = std::move(mo);
     78         assert(m.get_allocator() == A());
     79         assert(m.key_comp() == C(5));
     80         assert(m.size() == 0);
     81         assert(distance(m.begin(), m.end()) == 0);
     82 
     83         assert(mo.get_allocator() == A());
     84         assert(mo.key_comp() == C(5));
     85         assert(mo.size() == 0);
     86         assert(distance(mo.begin(), mo.end()) == 0);
     87     }
     88     {
     89         V ar[] =
     90         {
     91             V(1, 1),
     92             V(1, 1.5),
     93             V(1, 2),
     94             V(2, 1),
     95             V(2, 1.5),
     96             V(2, 2),
     97             V(3, 1),
     98             V(3, 1.5),
     99             V(3, 2),
    100         };
    101         typedef test_compare<std::less<int> > C;
    102         typedef min_allocator<V> A;
    103         std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
    104         std::map<int, double, C, A> m = std::move(mo);
    105         assert(m.get_allocator() == A());
    106         assert(m.key_comp() == C(5));
    107         assert(m.size() == 3);
    108         assert(distance(m.begin(), m.end()) == 3);
    109         assert(*m.begin() == V(1, 1));
    110         assert(*next(m.begin()) == V(2, 1));
    111         assert(*next(m.begin(), 2) == V(3, 1));
    112 
    113         assert(mo.get_allocator() == A());
    114         assert(mo.key_comp() == C(5));
    115         assert(mo.size() == 0);
    116         assert(distance(mo.begin(), mo.end()) == 0);
    117     }
    118 #endif
    119 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    120 }
    121