Home | History | Annotate | Download | only in unord.multimap.modifiers
      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 // <unordered_map>
     11 
     12 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
     13 //           class Alloc = allocator<pair<const Key, T>>>
     14 // class unordered_multimap
     15 
     16 // template <class P,
     17 //           class = typename enable_if<is_convertible<P, value_type>::value>::type>
     18 //     iterator insert(const_iterator p, P&& x);
     19 
     20 #if _LIBCPP_DEBUG >= 1
     21 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
     22 #endif
     23 
     24 #include <unordered_map>
     25 #include <cassert>
     26 
     27 #include "../../../MoveOnly.h"
     28 #include "min_allocator.h"
     29 
     30 int main()
     31 {
     32     {
     33         typedef std::unordered_multimap<double, int> C;
     34         typedef C::iterator R;
     35         typedef std::pair<double, short> P;
     36         C c;
     37         C::const_iterator e = c.end();
     38         R r = c.insert(e, P(3.5, 3));
     39         assert(c.size() == 1);
     40         assert(r->first == 3.5);
     41         assert(r->second == 3);
     42 
     43         r = c.insert(r, P(3.5, 4));
     44         assert(c.size() == 2);
     45         assert(r->first == 3.5);
     46         assert(r->second == 4);
     47 
     48         r = c.insert(c.end(), P(4.5, 4));
     49         assert(c.size() == 3);
     50         assert(r->first == 4.5);
     51         assert(r->second == 4);
     52 
     53         r = c.insert(c.end(), P(5.5, 4));
     54         assert(c.size() == 4);
     55         assert(r->first == 5.5);
     56         assert(r->second == 4);
     57     }
     58 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     59     {
     60         typedef std::unordered_multimap<MoveOnly, MoveOnly> C;
     61         typedef C::iterator R;
     62         typedef std::pair<MoveOnly, MoveOnly> P;
     63         C c;
     64         C::const_iterator e = c.end();
     65         R r = c.insert(e, P(3, 3));
     66         assert(c.size() == 1);
     67         assert(r->first == 3);
     68         assert(r->second == 3);
     69 
     70         r = c.insert(r, P(3, 4));
     71         assert(c.size() == 2);
     72         assert(r->first == 3);
     73         assert(r->second == 4);
     74 
     75         r = c.insert(c.end(), P(4, 4));
     76         assert(c.size() == 3);
     77         assert(r->first == 4);
     78         assert(r->second == 4);
     79 
     80         r = c.insert(c.end(), P(5, 4));
     81         assert(c.size() == 4);
     82         assert(r->first == 5);
     83         assert(r->second == 4);
     84     }
     85 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     86 #if __cplusplus >= 201103L
     87     {
     88         typedef std::unordered_multimap<double, int, std::hash<double>, std::equal_to<double>,
     89                             min_allocator<std::pair<const double, int>>> C;
     90         typedef C::iterator R;
     91         typedef std::pair<double, short> P;
     92         C c;
     93         C::const_iterator e = c.end();
     94         R r = c.insert(e, P(3.5, 3));
     95         assert(c.size() == 1);
     96         assert(r->first == 3.5);
     97         assert(r->second == 3);
     98 
     99         r = c.insert(r, P(3.5, 4));
    100         assert(c.size() == 2);
    101         assert(r->first == 3.5);
    102         assert(r->second == 4);
    103 
    104         r = c.insert(c.end(), P(4.5, 4));
    105         assert(c.size() == 3);
    106         assert(r->first == 4.5);
    107         assert(r->second == 4);
    108 
    109         r = c.insert(c.end(), P(5.5, 4));
    110         assert(c.size() == 4);
    111         assert(r->first == 5.5);
    112         assert(r->second == 4);
    113     }
    114 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    115     {
    116         typedef std::unordered_multimap<MoveOnly, MoveOnly, std::hash<MoveOnly>, std::equal_to<MoveOnly>,
    117                             min_allocator<std::pair<const MoveOnly, MoveOnly>>> C;
    118         typedef C::iterator R;
    119         typedef std::pair<MoveOnly, MoveOnly> P;
    120         C c;
    121         C::const_iterator e = c.end();
    122         R r = c.insert(e, P(3, 3));
    123         assert(c.size() == 1);
    124         assert(r->first == 3);
    125         assert(r->second == 3);
    126 
    127         r = c.insert(r, P(3, 4));
    128         assert(c.size() == 2);
    129         assert(r->first == 3);
    130         assert(r->second == 4);
    131 
    132         r = c.insert(c.end(), P(4, 4));
    133         assert(c.size() == 3);
    134         assert(r->first == 4);
    135         assert(r->second == 4);
    136 
    137         r = c.insert(c.end(), P(5, 4));
    138         assert(c.size() == 4);
    139         assert(r->first == 5);
    140         assert(r->second == 4);
    141     }
    142 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    143 #if _LIBCPP_DEBUG >= 1
    144     {
    145         typedef std::unordered_multimap<double, int> C;
    146         typedef C::iterator R;
    147         typedef C::value_type P;
    148         C c;
    149         C c2;
    150         C::const_iterator e = c2.end();
    151         R r = c.insert(e, P(3.5, 3));
    152         assert(false);
    153     }
    154 #endif
    155 #endif
    156 }
    157