emplace_hint.pass.cpp revision f890d9bfaadc13df40bb74e95cebd53ec826f932
18bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//===----------------------------------------------------------------------===//
28bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//
38bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//                     The LLVM Compiler Infrastructure
48bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//
58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// This file is dual licensed under the MIT and the University of Illinois Open
68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Source Licenses. See LICENSE.TXT for details.
78bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//
88bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//===----------------------------------------------------------------------===//
98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// <unordered_map>
118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//           class Alloc = allocator<pair<const Key, T>>>
148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// class unordered_map
158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// template <class... Args>
178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//     iterator emplace_hint(const_iterator p, Args&&... args);
188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include <unordered_map>
208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include <cassert>
218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "../../../Emplaceable.h"
238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "../../../min_allocator.h"
248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)int main()
268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles){
278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    {
298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        typedef std::unordered_map<int, Emplaceable> C;
308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        typedef C::iterator R;
318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        C c;
328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        C::const_iterator e = c.end();
338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                                                          std::forward_as_tuple());
358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(c.size() == 1);
368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(r->first == 3);
378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(r->second == Emplaceable());
388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(c.size() == 2);
418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(r->first == 4);
428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(r->second == Emplaceable(5, 6));
438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5),
458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                                                       std::forward_as_tuple(6, 7));
468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(c.size() == 3);
478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(r->first == 5);
488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        assert(r->second == Emplaceable(6, 7));
498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    }
50#if __cplusplus >= 201103L
51    {
52        typedef std::unordered_map<int, Emplaceable, std::hash<int>, std::equal_to<int>,
53                            min_allocator<std::pair<const int, Emplaceable>>> C;
54        typedef C::iterator R;
55        C c;
56        C::const_iterator e = c.end();
57        R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3),
58                                                          std::forward_as_tuple());
59        assert(c.size() == 1);
60        assert(r->first == 3);
61        assert(r->second == Emplaceable());
62
63        r = c.emplace_hint(c.end(), std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
64        assert(c.size() == 2);
65        assert(r->first == 4);
66        assert(r->second == Emplaceable(5, 6));
67
68        r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5),
69                                                       std::forward_as_tuple(6, 7));
70        assert(c.size() == 3);
71        assert(r->first == 5);
72        assert(r->second == Emplaceable(6, 7));
73    }
74#endif
75#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
76}
77