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