Home | History | Annotate | Download | only in unord.map.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_map
     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 
     28 int main()
     29 {
     30     {
     31         typedef std::unordered_map<int, Emplaceable> C;
     32         typedef C::iterator R;
     33         C c;
     34         C::const_iterator e = c.end();
     35         R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
     36                                                           std::forward_as_tuple());
     37         assert(c.size() == 1);
     38         assert(r->first == 3);
     39         assert(r->second == Emplaceable());
     40 
     41         r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
     42         assert(c.size() == 2);
     43         assert(r->first == 4);
     44         assert(r->second == Emplaceable(5, 6));
     45 
     46         r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5),
     47                                                        std::forward_as_tuple(6, 7));
     48         assert(c.size() == 3);
     49         assert(r->first == 5);
     50         assert(r->second == Emplaceable(6, 7));
     51     }
     52     {
     53         typedef std::unordered_map<int, Emplaceable, std::hash<int>, std::equal_to<int>,
     54                             min_allocator<std::pair<const int, Emplaceable>>> C;
     55         typedef C::iterator R;
     56         C c;
     57         C::const_iterator e = c.end();
     58         R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
     59                                                           std::forward_as_tuple());
     60         assert(c.size() == 1);
     61         assert(r->first == 3);
     62         assert(r->second == Emplaceable());
     63 
     64         r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
     65         assert(c.size() == 2);
     66         assert(r->first == 4);
     67         assert(r->second == Emplaceable(5, 6));
     68 
     69         r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5),
     70                                                        std::forward_as_tuple(6, 7));
     71         assert(c.size() == 3);
     72         assert(r->first == 5);
     73         assert(r->second == Emplaceable(6, 7));
     74     }
     75 }
     76