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 //       iterator upper_bound(const key_type& k);
     15 // const_iterator upper_bound(const key_type& k) const;
     16 
     17 #include <map>
     18 #include <cassert>
     19 
     20 #include "../../../min_allocator.h"
     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::iterator 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         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     42         R r = m.upper_bound(4);
     43         assert(r == m.begin());
     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(10);
     55         assert(r == m.end());
     56     }
     57     {
     58         typedef M::const_iterator R;
     59         V ar[] =
     60         {
     61             V(5, 1),
     62             V(5, 2),
     63             V(5, 3),
     64             V(7, 1),
     65             V(7, 2),
     66             V(7, 3),
     67             V(9, 1),
     68             V(9, 2),
     69             V(9, 3)
     70         };
     71         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     72         R r = m.upper_bound(4);
     73         assert(r == m.begin());
     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(10);
     85         assert(r == m.end());
     86     }
     87     }
     88 #if __cplusplus >= 201103L
     89     {
     90     typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
     91     {
     92         typedef M::iterator R;
     93         V ar[] =
     94         {
     95             V(5, 1),
     96             V(5, 2),
     97             V(5, 3),
     98             V(7, 1),
     99             V(7, 2),
    100             V(7, 3),
    101             V(9, 1),
    102             V(9, 2),
    103             V(9, 3)
    104         };
    105         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    106         R r = m.upper_bound(4);
    107         assert(r == m.begin());
    108         r = m.upper_bound(5);
    109         assert(r == next(m.begin(), 3));
    110         r = m.upper_bound(6);
    111         assert(r == next(m.begin(), 3));
    112         r = m.upper_bound(7);
    113         assert(r == next(m.begin(), 6));
    114         r = m.upper_bound(8);
    115         assert(r == next(m.begin(), 6));
    116         r = m.upper_bound(9);
    117         assert(r == next(m.begin(), 9));
    118         r = m.upper_bound(10);
    119         assert(r == m.end());
    120     }
    121     {
    122         typedef M::const_iterator R;
    123         V ar[] =
    124         {
    125             V(5, 1),
    126             V(5, 2),
    127             V(5, 3),
    128             V(7, 1),
    129             V(7, 2),
    130             V(7, 3),
    131             V(9, 1),
    132             V(9, 2),
    133             V(9, 3)
    134         };
    135         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    136         R r = m.upper_bound(4);
    137         assert(r == m.begin());
    138         r = m.upper_bound(5);
    139         assert(r == next(m.begin(), 3));
    140         r = m.upper_bound(6);
    141         assert(r == next(m.begin(), 3));
    142         r = m.upper_bound(7);
    143         assert(r == next(m.begin(), 6));
    144         r = m.upper_bound(8);
    145         assert(r == next(m.begin(), 6));
    146         r = m.upper_bound(9);
    147         assert(r == next(m.begin(), 9));
    148         r = m.upper_bound(10);
    149         assert(r == m.end());
    150     }
    151     }
    152 #endif
    153 }
    154