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... Args>
     17 //     iterator emplace_hint(const_iterator p, Args&&... args);
     18 
     19 #if _LIBCPP_DEBUG >= 1
     20 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
     21 #endif
     22 
     23 #include <unordered_map>
     24 #include <cassert>
     25 
     26 #include "../../../Emplaceable.h"
     27 #include "min_allocator.h"
     28 #include "test_macros.h"
     29 
     30 int main()
     31 {
     32 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     33     {
     34         typedef std::unordered_multimap<int, Emplaceable> C;
     35         typedef C::iterator R;
     36         C c;
     37         C::const_iterator e = c.end();
     38         R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
     39                                                           std::forward_as_tuple());
     40         assert(c.size() == 1);
     41         assert(r->first == 3);
     42         assert(r->second == Emplaceable());
     43 
     44         r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(3, Emplaceable(5, 6)));
     45         assert(c.size() == 2);
     46         assert(r->first == 3);
     47         assert(r->second == Emplaceable(5, 6));
     48         LIBCPP_ASSERT(r == next(c.begin()));
     49 
     50         r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(3),
     51                                                         std::forward_as_tuple(6, 7));
     52         assert(c.size() == 3);
     53         assert(r->first == 3);
     54         assert(r->second == Emplaceable(6, 7));
     55         LIBCPP_ASSERT(r == next(c.begin()));
     56         r = c.begin();
     57         assert(r->first == 3);
     58         LIBCPP_ASSERT(r->second == Emplaceable());
     59         r = next(r, 2);
     60         assert(r->first == 3);
     61         LIBCPP_ASSERT(r->second == Emplaceable(5, 6));
     62     }
     63 #if TEST_STD_VER >= 11
     64     {
     65         typedef std::unordered_multimap<int, Emplaceable, std::hash<int>, std::equal_to<int>,
     66                             min_allocator<std::pair<const int, Emplaceable>>> C;
     67         typedef C::iterator R;
     68         C c;
     69         C::const_iterator e = c.end();
     70         R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
     71                                                           std::forward_as_tuple());
     72         assert(c.size() == 1);
     73         assert(r->first == 3);
     74         assert(r->second == Emplaceable());
     75 
     76         r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(3, Emplaceable(5, 6)));
     77         assert(c.size() == 2);
     78         assert(r->first == 3);
     79         assert(r->second == Emplaceable(5, 6));
     80         LIBCPP_ASSERT(r == next(c.begin()));
     81 
     82         r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(3),
     83                                                         std::forward_as_tuple(6, 7));
     84         assert(c.size() == 3);
     85         assert(r->first == 3);
     86         assert(r->second == Emplaceable(6, 7));
     87         LIBCPP_ASSERT(r == next(c.begin()));
     88         r = c.begin();
     89         assert(r->first == 3);
     90         LIBCPP_ASSERT(r->second == Emplaceable());
     91         r = next(r, 2);
     92         assert(r->first == 3);
     93         LIBCPP_ASSERT(r->second == Emplaceable(5, 6));
     94     }
     95 #endif
     96 #if _LIBCPP_DEBUG >= 1
     97     {
     98         typedef std::unordered_multimap<int, Emplaceable> C;
     99         typedef C::iterator R;
    100         typedef C::value_type P;
    101         C c;
    102         C c2;
    103         R r = c.emplace_hint(c2.end(), std::piecewise_construct,
    104                                        std::forward_as_tuple(3),
    105                                        std::forward_as_tuple());
    106         assert(false);
    107     }
    108 #endif
    109 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    110 }
    111