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 "test_macros.h"
     21 #include "min_allocator.h"
     22 #include "private_constructor.hpp"
     23 #include "is_transparent.h"
     24 
     25 int main()
     26 {
     27     typedef std::pair<const int, double> V;
     28     {
     29     typedef std::multimap<int, double> M;
     30     {
     31         typedef M::iterator R;
     32         V ar[] =
     33         {
     34             V(5, 1),
     35             V(5, 2),
     36             V(5, 3),
     37             V(7, 1),
     38             V(7, 2),
     39             V(7, 3),
     40             V(9, 1),
     41             V(9, 2),
     42             V(9, 3)
     43         };
     44         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     45         R r = m.upper_bound(4);
     46         assert(r == m.begin());
     47         r = m.upper_bound(5);
     48         assert(r == next(m.begin(), 3));
     49         r = m.upper_bound(6);
     50         assert(r == next(m.begin(), 3));
     51         r = m.upper_bound(7);
     52         assert(r == next(m.begin(), 6));
     53         r = m.upper_bound(8);
     54         assert(r == next(m.begin(), 6));
     55         r = m.upper_bound(9);
     56         assert(r == next(m.begin(), 9));
     57         r = m.upper_bound(10);
     58         assert(r == m.end());
     59     }
     60     {
     61         typedef M::const_iterator R;
     62         V ar[] =
     63         {
     64             V(5, 1),
     65             V(5, 2),
     66             V(5, 3),
     67             V(7, 1),
     68             V(7, 2),
     69             V(7, 3),
     70             V(9, 1),
     71             V(9, 2),
     72             V(9, 3)
     73         };
     74         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     75         R r = m.upper_bound(4);
     76         assert(r == m.begin());
     77         r = m.upper_bound(5);
     78         assert(r == next(m.begin(), 3));
     79         r = m.upper_bound(6);
     80         assert(r == next(m.begin(), 3));
     81         r = m.upper_bound(7);
     82         assert(r == next(m.begin(), 6));
     83         r = m.upper_bound(8);
     84         assert(r == next(m.begin(), 6));
     85         r = m.upper_bound(9);
     86         assert(r == next(m.begin(), 9));
     87         r = m.upper_bound(10);
     88         assert(r == m.end());
     89     }
     90     }
     91 #if TEST_STD_VER >= 11
     92     {
     93     typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
     94     {
     95         typedef M::iterator R;
     96         V ar[] =
     97         {
     98             V(5, 1),
     99             V(5, 2),
    100             V(5, 3),
    101             V(7, 1),
    102             V(7, 2),
    103             V(7, 3),
    104             V(9, 1),
    105             V(9, 2),
    106             V(9, 3)
    107         };
    108         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    109         R r = m.upper_bound(4);
    110         assert(r == m.begin());
    111         r = m.upper_bound(5);
    112         assert(r == next(m.begin(), 3));
    113         r = m.upper_bound(6);
    114         assert(r == next(m.begin(), 3));
    115         r = m.upper_bound(7);
    116         assert(r == next(m.begin(), 6));
    117         r = m.upper_bound(8);
    118         assert(r == next(m.begin(), 6));
    119         r = m.upper_bound(9);
    120         assert(r == next(m.begin(), 9));
    121         r = m.upper_bound(10);
    122         assert(r == m.end());
    123     }
    124     {
    125         typedef M::const_iterator R;
    126         V ar[] =
    127         {
    128             V(5, 1),
    129             V(5, 2),
    130             V(5, 3),
    131             V(7, 1),
    132             V(7, 2),
    133             V(7, 3),
    134             V(9, 1),
    135             V(9, 2),
    136             V(9, 3)
    137         };
    138         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    139         R r = m.upper_bound(4);
    140         assert(r == m.begin());
    141         r = m.upper_bound(5);
    142         assert(r == next(m.begin(), 3));
    143         r = m.upper_bound(6);
    144         assert(r == next(m.begin(), 3));
    145         r = m.upper_bound(7);
    146         assert(r == next(m.begin(), 6));
    147         r = m.upper_bound(8);
    148         assert(r == next(m.begin(), 6));
    149         r = m.upper_bound(9);
    150         assert(r == next(m.begin(), 9));
    151         r = m.upper_bound(10);
    152         assert(r == m.end());
    153     }
    154     }
    155 #endif
    156 #if TEST_STD_VER > 11
    157     {
    158     typedef std::multimap<int, double, std::less<>> M;
    159     typedef M::iterator R;
    160     V ar[] =
    161     {
    162         V(5, 1),
    163         V(5, 2),
    164         V(5, 3),
    165         V(7, 1),
    166         V(7, 2),
    167         V(7, 3),
    168         V(9, 1),
    169         V(9, 2),
    170         V(9, 3)
    171     };
    172     M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    173     R r = m.upper_bound(4);
    174     assert(r == m.begin());
    175     r = m.upper_bound(5);
    176     assert(r == next(m.begin(), 3));
    177     r = m.upper_bound(6);
    178     assert(r == next(m.begin(), 3));
    179     r = m.upper_bound(7);
    180     assert(r == next(m.begin(), 6));
    181     r = m.upper_bound(8);
    182     assert(r == next(m.begin(), 6));
    183     r = m.upper_bound(9);
    184     assert(r == next(m.begin(), 9));
    185     r = m.upper_bound(10);
    186     assert(r == m.end());
    187 
    188     r = m.upper_bound(C2Int(4));
    189     assert(r == m.begin());
    190     r = m.upper_bound(C2Int(5));
    191     assert(r == next(m.begin(), 3));
    192     r = m.upper_bound(C2Int(6));
    193     assert(r == next(m.begin(), 3));
    194     r = m.upper_bound(C2Int(7));
    195     assert(r == next(m.begin(), 6));
    196     r = m.upper_bound(C2Int(8));
    197     assert(r == next(m.begin(), 6));
    198     r = m.upper_bound(C2Int(9));
    199     assert(r == next(m.begin(), 9));
    200     r = m.upper_bound(C2Int(10));
    201     }
    202 
    203     {
    204     typedef PrivateConstructor PC;
    205     typedef std::multimap<PC, double, std::less<>> M;
    206     typedef M::iterator R;
    207 
    208     M m;
    209     m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
    210     m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
    211     m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
    212     m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
    213     m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
    214     m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
    215     m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
    216     m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
    217     m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
    218 
    219     R r = m.upper_bound(4);
    220     assert(r == m.begin());
    221     r = m.upper_bound(5);
    222     assert(r == next(m.begin(), 3));
    223     r = m.upper_bound(6);
    224     assert(r == next(m.begin(), 3));
    225     r = m.upper_bound(7);
    226     assert(r == next(m.begin(), 6));
    227     r = m.upper_bound(8);
    228     assert(r == next(m.begin(), 6));
    229     r = m.upper_bound(9);
    230     assert(r == next(m.begin(), 9));
    231     r = m.upper_bound(10);
    232     assert(r == m.end());
    233     }
    234 
    235 #endif
    236 }
    237