Home | History | Annotate | Download | only in multimap
      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 begin();
     15 // const_iterator begin() const;
     16 //       iterator end();
     17 // const_iterator end()   const;
     18 //
     19 //       reverse_iterator rbegin();
     20 // const_reverse_iterator rbegin() const;
     21 //       reverse_iterator rend();
     22 // const_reverse_iterator rend()   const;
     23 //
     24 // const_iterator         cbegin()  const;
     25 // const_iterator         cend()    const;
     26 // const_reverse_iterator crbegin() const;
     27 // const_reverse_iterator crend()   const;
     28 
     29 #include <map>
     30 #include <cassert>
     31 
     32 #include "min_allocator.h"
     33 
     34 int main()
     35 {
     36     {
     37         typedef std::pair<const int, double> V;
     38         V ar[] =
     39         {
     40             V(1, 1),
     41             V(1, 1.5),
     42             V(1, 2),
     43             V(2, 1),
     44             V(2, 1.5),
     45             V(2, 2),
     46             V(3, 1),
     47             V(3, 1.5),
     48             V(3, 2),
     49             V(4, 1),
     50             V(4, 1.5),
     51             V(4, 2),
     52             V(5, 1),
     53             V(5, 1.5),
     54             V(5, 2),
     55             V(6, 1),
     56             V(6, 1.5),
     57             V(6, 2),
     58             V(7, 1),
     59             V(7, 1.5),
     60             V(7, 2),
     61             V(8, 1),
     62             V(8, 1.5),
     63             V(8, 2)
     64         };
     65         std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     66         assert(std::distance(m.begin(), m.end()) == m.size());
     67         assert(std::distance(m.rbegin(), m.rend()) == m.size());
     68         std::multimap<int, double>::iterator i;
     69         i = m.begin();
     70         std::multimap<int, double>::const_iterator k = i;
     71         assert(i == k);
     72         for (int j = 1; j <= 8; ++j)
     73             for (double d = 1; d <= 2; d += .5, ++i)
     74             {
     75                 assert(i->first == j);
     76                 assert(i->second == d);
     77                 i->second = 2.5;
     78                 assert(i->second == 2.5);
     79             }
     80     }
     81     {
     82         typedef std::pair<const int, double> V;
     83         V ar[] =
     84         {
     85             V(1, 1),
     86             V(1, 1.5),
     87             V(1, 2),
     88             V(2, 1),
     89             V(2, 1.5),
     90             V(2, 2),
     91             V(3, 1),
     92             V(3, 1.5),
     93             V(3, 2),
     94             V(4, 1),
     95             V(4, 1.5),
     96             V(4, 2),
     97             V(5, 1),
     98             V(5, 1.5),
     99             V(5, 2),
    100             V(6, 1),
    101             V(6, 1.5),
    102             V(6, 2),
    103             V(7, 1),
    104             V(7, 1.5),
    105             V(7, 2),
    106             V(8, 1),
    107             V(8, 1.5),
    108             V(8, 2)
    109         };
    110         const std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    111         assert(std::distance(m.begin(), m.end()) == m.size());
    112         assert(std::distance(m.cbegin(), m.cend()) == m.size());
    113         assert(std::distance(m.rbegin(), m.rend()) == m.size());
    114         assert(std::distance(m.crbegin(), m.crend()) == m.size());
    115         std::multimap<int, double>::const_iterator i;
    116         i = m.begin();
    117         for (int j = 1; j <= 8; ++j)
    118             for (double d = 1; d <= 2; d += .5, ++i)
    119             {
    120                 assert(i->first == j);
    121                 assert(i->second == d);
    122             }
    123     }
    124 #if __cplusplus >= 201103L
    125     {
    126         typedef std::pair<const int, double> V;
    127         V ar[] =
    128         {
    129             V(1, 1),
    130             V(1, 1.5),
    131             V(1, 2),
    132             V(2, 1),
    133             V(2, 1.5),
    134             V(2, 2),
    135             V(3, 1),
    136             V(3, 1.5),
    137             V(3, 2),
    138             V(4, 1),
    139             V(4, 1.5),
    140             V(4, 2),
    141             V(5, 1),
    142             V(5, 1.5),
    143             V(5, 2),
    144             V(6, 1),
    145             V(6, 1.5),
    146             V(6, 2),
    147             V(7, 1),
    148             V(7, 1.5),
    149             V(7, 2),
    150             V(8, 1),
    151             V(8, 1.5),
    152             V(8, 2)
    153         };
    154         std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    155         assert(std::distance(m.begin(), m.end()) == m.size());
    156         assert(std::distance(m.rbegin(), m.rend()) == m.size());
    157         std::multimap<int, double, std::less<int>, min_allocator<V>>::iterator i;
    158         i = m.begin();
    159         std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator k = i;
    160         assert(i == k);
    161         for (int j = 1; j <= 8; ++j)
    162             for (double d = 1; d <= 2; d += .5, ++i)
    163             {
    164                 assert(i->first == j);
    165                 assert(i->second == d);
    166                 i->second = 2.5;
    167                 assert(i->second == 2.5);
    168             }
    169     }
    170     {
    171         typedef std::pair<const int, double> V;
    172         V ar[] =
    173         {
    174             V(1, 1),
    175             V(1, 1.5),
    176             V(1, 2),
    177             V(2, 1),
    178             V(2, 1.5),
    179             V(2, 2),
    180             V(3, 1),
    181             V(3, 1.5),
    182             V(3, 2),
    183             V(4, 1),
    184             V(4, 1.5),
    185             V(4, 2),
    186             V(5, 1),
    187             V(5, 1.5),
    188             V(5, 2),
    189             V(6, 1),
    190             V(6, 1.5),
    191             V(6, 2),
    192             V(7, 1),
    193             V(7, 1.5),
    194             V(7, 2),
    195             V(8, 1),
    196             V(8, 1.5),
    197             V(8, 2)
    198         };
    199         const std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
    200         assert(std::distance(m.begin(), m.end()) == m.size());
    201         assert(std::distance(m.cbegin(), m.cend()) == m.size());
    202         assert(std::distance(m.rbegin(), m.rend()) == m.size());
    203         assert(std::distance(m.crbegin(), m.crend()) == m.size());
    204         std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator i;
    205         i = m.begin();
    206         for (int j = 1; j <= 8; ++j)
    207             for (double d = 1; d <= 2; d += .5, ++i)
    208             {
    209                 assert(i->first == j);
    210                 assert(i->second == d);
    211             }
    212     }
    213 #endif
    214 #if _LIBCPP_STD_VER > 11
    215     { // N3644 testing
    216         typedef std::multimap<int, double> C;
    217         C::iterator ii1{}, ii2{};
    218         C::iterator ii4 = ii1;
    219         C::const_iterator cii{};
    220         assert ( ii1 == ii2 );
    221         assert ( ii1 == ii4 );
    222 
    223         assert (!(ii1 != ii2 ));
    224 
    225         assert ( (ii1 == cii ));
    226         assert ( (cii == ii1 ));
    227         assert (!(ii1 != cii ));
    228         assert (!(cii != ii1 ));
    229     }
    230 #endif
    231 }
    232