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