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