libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

initializer_list_compare.pass.cpp (2311B)


      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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <map>
     13 
     14 // class multimap
     15 
     16 // multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
     17 
     18 #include <map>
     19 #include <cassert>
     20 #include "../../../test_compare.h"
     21 #include "min_allocator.h"
     22 
     23 int main()
     24 {
     25     {
     26     typedef test_compare<std::less<int> > Cmp;
     27     typedef std::multimap<int, double, Cmp> C;
     28     typedef C::value_type V;
     29     C m(
     30            {
     31                {1, 1},
     32                {1, 1.5},
     33                {1, 2},
     34                {2, 1},
     35                {2, 1.5},
     36                {2, 2},
     37                {3, 1},
     38                {3, 1.5},
     39                {3, 2}
     40            },
     41            Cmp(4)
     42         );
     43     assert(m.size() == 9);
     44     assert(distance(m.begin(), m.end()) == 9);
     45     C::const_iterator i = m.cbegin();
     46     assert(*i == V(1, 1));
     47     assert(*++i == V(1, 1.5));
     48     assert(*++i == V(1, 2));
     49     assert(*++i == V(2, 1));
     50     assert(*++i == V(2, 1.5));
     51     assert(*++i == V(2, 2));
     52     assert(*++i == V(3, 1));
     53     assert(*++i == V(3, 1.5));
     54     assert(*++i == V(3, 2));
     55     assert(m.key_comp() == Cmp(4));
     56     }
     57     {
     58     typedef test_compare<std::less<int> > Cmp;
     59     typedef std::multimap<int, double, Cmp, min_allocator<std::pair<const int, double>>> C;
     60     typedef C::value_type V;
     61     C m(
     62            {
     63                {1, 1},
     64                {1, 1.5},
     65                {1, 2},
     66                {2, 1},
     67                {2, 1.5},
     68                {2, 2},
     69                {3, 1},
     70                {3, 1.5},
     71                {3, 2}
     72            },
     73            Cmp(4)
     74         );
     75     assert(m.size() == 9);
     76     assert(distance(m.begin(), m.end()) == 9);
     77     C::const_iterator i = m.cbegin();
     78     assert(*i == V(1, 1));
     79     assert(*++i == V(1, 1.5));
     80     assert(*++i == V(1, 2));
     81     assert(*++i == V(2, 1));
     82     assert(*++i == V(2, 1.5));
     83     assert(*++i == V(2, 2));
     84     assert(*++i == V(3, 1));
     85     assert(*++i == V(3, 1.5));
     86     assert(*++i == V(3, 2));
     87     assert(m.key_comp() == Cmp(4));
     88     }
     89 }