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