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 // template <class InputIterator>
     15 //     multimap(InputIterator first, InputIterator last,
     16 //              const key_compare& comp);
     17 
     18 #include <map>
     19 #include <cassert>
     20 
     21 #include "../../../test_compare.h"
     22 #include "min_allocator.h"
     23 
     24 int main()
     25 {
     26     {
     27     typedef std::pair<const int, double> V;
     28     V ar[] =
     29     {
     30         V(1, 1),
     31         V(1, 1.5),
     32         V(1, 2),
     33         V(2, 1),
     34         V(2, 1.5),
     35         V(2, 2),
     36         V(3, 1),
     37         V(3, 1.5),
     38         V(3, 2),
     39     };
     40     typedef test_compare<std::less<int> > C;
     41     std::multimap<int, double, C> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5));
     42     assert(m.key_comp() == C(5));
     43     assert(m.size() == 9);
     44     assert(distance(m.begin(), m.end()) == 9);
     45     assert(*m.begin() == V(1, 1));
     46     assert(*next(m.begin()) == V(1, 1.5));
     47     assert(*next(m.begin(), 2) == V(1, 2));
     48     assert(*next(m.begin(), 3) == V(2, 1));
     49     assert(*next(m.begin(), 4) == V(2, 1.5));
     50     assert(*next(m.begin(), 5) == V(2, 2));
     51     assert(*next(m.begin(), 6) == V(3, 1));
     52     assert(*next(m.begin(), 7) == V(3, 1.5));
     53     assert(*next(m.begin(), 8) == V(3, 2));
     54     }
     55 #if __cplusplus >= 201103L
     56     {
     57     typedef std::pair<const int, double> V;
     58     V ar[] =
     59     {
     60         V(1, 1),
     61         V(1, 1.5),
     62         V(1, 2),
     63         V(2, 1),
     64         V(2, 1.5),
     65         V(2, 2),
     66         V(3, 1),
     67         V(3, 1.5),
     68         V(3, 2),
     69     };
     70     typedef test_compare<std::less<int> > C;
     71     std::multimap<int, double, C, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5));
     72     assert(m.key_comp() == C(5));
     73     assert(m.size() == 9);
     74     assert(distance(m.begin(), m.end()) == 9);
     75     assert(*m.begin() == V(1, 1));
     76     assert(*next(m.begin()) == V(1, 1.5));
     77     assert(*next(m.begin(), 2) == V(1, 2));
     78     assert(*next(m.begin(), 3) == V(2, 1));
     79     assert(*next(m.begin(), 4) == V(2, 1.5));
     80     assert(*next(m.begin(), 5) == V(2, 2));
     81     assert(*next(m.begin(), 6) == V(3, 1));
     82     assert(*next(m.begin(), 7) == V(3, 1.5));
     83     assert(*next(m.begin(), 8) == V(3, 2));
     84     }
     85 #endif
     86 }
     87