Home | History | Annotate | Download | only in multimap.ops
      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 // size_type count(const key_type& k) const;
     15 
     16 #include <map>
     17 #include <cassert>
     18 
     19 #include "min_allocator.h"
     20 #include "private_constructor.hpp"
     21 
     22 int main()
     23 {
     24     typedef std::pair<const int, double> V;
     25     {
     26     typedef std::multimap<int, double> M;
     27     {
     28         typedef M::size_type R;
     29         V ar[] =
     30         {
     31             V(5, 1),
     32             V(5, 2),
     33             V(5, 3),
     34             V(7, 1),
     35             V(7, 2),
     36             V(7, 3),
     37             V(9, 1),
     38             V(9, 2),
     39             V(9, 3)
     40         };
     41         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     42         R r = m.count(4);
     43         assert(r == 0);
     44         r = m.count(5);
     45         assert(r == 3);
     46         r = m.count(6);
     47         assert(r == 0);
     48         r = m.count(7);
     49         assert(r == 3);
     50         r = m.count(8);
     51         assert(r == 0);
     52         r = m.count(9);
     53         assert(r == 3);
     54         r = m.count(10);
     55         assert(r == 0);
     56     }
     57     }
     58 #if __cplusplus >= 201103L
     59     {
     60     typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
     61     {
     62         typedef M::size_type R;
     63         V ar[] =
     64         {
     65             V(5, 1),
     66             V(5, 2),
     67             V(5, 3),
     68             V(7, 1),
     69             V(7, 2),
     70             V(7, 3),
     71             V(9, 1),
     72             V(9, 2),
     73             V(9, 3)
     74         };
     75         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     76         R r = m.count(4);
     77         assert(r == 0);
     78         r = m.count(5);
     79         assert(r == 3);
     80         r = m.count(6);
     81         assert(r == 0);
     82         r = m.count(7);
     83         assert(r == 3);
     84         r = m.count(8);
     85         assert(r == 0);
     86         r = m.count(9);
     87         assert(r == 3);
     88         r = m.count(10);
     89         assert(r == 0);
     90     }
     91     }
     92 #endif
     93 
     94 #if _LIBCPP_STD_VER > 11
     95     {
     96     typedef std::multimap<int, double, std::less<>> M;
     97     typedef M::size_type R;
     98     V ar[] =
     99     {
    100         V(5, 1),
    101         V(5, 2),
    102         V(5, 3),
    103         V(7, 1),
    104         V(7, 2),
    105         V(7, 3),
    106         V(9, 1),
    107         V(9, 2),
    108         V(9, 3)
    109     };
    110     const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    111     R r = m.count(4);
    112     assert(r == 0);
    113     r = m.count(5);
    114     assert(r == 3);
    115     r = m.count(6);
    116     assert(r == 0);
    117     r = m.count(7);
    118     assert(r == 3);
    119     r = m.count(8);
    120     assert(r == 0);
    121     r = m.count(9);
    122     assert(r == 3);
    123     r = m.count(10);
    124     assert(r == 0);
    125     }
    126 
    127     {
    128     typedef PrivateConstructor PC;
    129     typedef std::multimap<PC, double, std::less<>> M;
    130     typedef M::size_type R;
    131 
    132     M m;
    133     m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
    134     m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
    135     m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
    136     m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
    137     m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
    138     m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
    139     m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
    140     m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
    141     m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
    142 
    143     R r = m.count(4);
    144     assert(r == 0);
    145     r = m.count(5);
    146     assert(r == 3);
    147     r = m.count(6);
    148     assert(r == 0);
    149     r = m.count(7);
    150     assert(r == 3);
    151     r = m.count(8);
    152     assert(r == 0);
    153     r = m.count(9);
    154     assert(r == 3);
    155     r = m.count(10);
    156     assert(r == 0);
    157     }
    158 #endif
    159 }
    160