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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <unordered_map>
     13 
     14 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
     15 //           class Alloc = allocator<pair<const Key, T>>>
     16 // class unordered_multimap
     17 
     18 // template <class... Args>
     19 //     iterator emplace_hint(const_iterator p, Args&&... args);
     20 
     21 
     22 #include <unordered_map>
     23 #include <cassert>
     24 
     25 #include "../../../Emplaceable.h"
     26 #include "min_allocator.h"
     27 #include "test_macros.h"
     28 
     29 int main()
     30 {
     31     {
     32         typedef std::unordered_multimap<int, Emplaceable> C;
     33         typedef C::iterator R;
     34         C c;
     35         C::const_iterator e = c.end();
     36         R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
     37                                                           std::forward_as_tuple());
     38         assert(c.size() == 1);
     39         assert(r->first == 3);
     40         assert(r->second == Emplaceable());
     41 
     42         r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(3, Emplaceable(5, 6)));
     43         assert(c.size() == 2);
     44         assert(r->first == 3);
     45         assert(r->second == Emplaceable(5, 6));
     46         LIBCPP_ASSERT(r == next(c.begin()));
     47 
     48         r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(3),
     49                                                         std::forward_as_tuple(6, 7));
     50         assert(c.size() == 3);
     51         assert(r->first == 3);
     52         assert(r->second == Emplaceable(6, 7));
     53         LIBCPP_ASSERT(r == next(c.begin()));
     54         r = c.begin();
     55         assert(r->first == 3);
     56         LIBCPP_ASSERT(r->second == Emplaceable());
     57         r = next(r, 2);
     58         assert(r->first == 3);
     59         LIBCPP_ASSERT(r->second == Emplaceable(5, 6));
     60     }
     61     {
     62         typedef std::unordered_multimap<int, Emplaceable, std::hash<int>, std::equal_to<int>,
     63                             min_allocator<std::pair<const int, Emplaceable>>> C;
     64         typedef C::iterator R;
     65         C c;
     66         C::const_iterator e = c.end();
     67         R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
     68                                                           std::forward_as_tuple());
     69         assert(c.size() == 1);
     70         assert(r->first == 3);
     71         assert(r->second == Emplaceable());
     72 
     73         r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(3, Emplaceable(5, 6)));
     74         assert(c.size() == 2);
     75         assert(r->first == 3);
     76         assert(r->second == Emplaceable(5, 6));
     77         LIBCPP_ASSERT(r == next(c.begin()));
     78 
     79         r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(3),
     80                                                         std::forward_as_tuple(6, 7));
     81         assert(c.size() == 3);
     82         assert(r->first == 3);
     83         assert(r->second == Emplaceable(6, 7));
     84         LIBCPP_ASSERT(r == next(c.begin()));
     85         r = c.begin();
     86         assert(r->first == 3);
     87         LIBCPP_ASSERT(r->second == Emplaceable());
     88         r = next(r, 2);
     89         assert(r->first == 3);
     90         LIBCPP_ASSERT(r->second == Emplaceable(5, 6));
     91     }
     92 }
     93