aboutsummaryrefslogtreecommitdiff
path: root/test/std/containers/associative/map/map.modifiers
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
commit61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch)
treeec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/containers/associative/map/map.modifiers
parentf857581820d15e410e9945d2fcd5f7163be25a96 (diff)
downloadsrc-61b9a7258a7693d7f3674a5a1daf7b036ff1d382.tar.gz
src-61b9a7258a7693d7f3674a5a1daf7b036ff1d382.zip
Import libc++ 3.7.0 release (r246257).vendor/libc++/libc++-release_370-r246257
Notes
Notes: svn path=/vendor/libc++/dist/; revision=287518 svn path=/vendor/libc++/libc++-release_370-r246257/; revision=287519; tag=vendor/libc++/libc++-release_370-r246257
Diffstat (limited to 'test/std/containers/associative/map/map.modifiers')
-rw-r--r--test/std/containers/associative/map/map.modifiers/clear.pass.cpp63
-rw-r--r--test/std/containers/associative/map/map.modifiers/emplace.pass.cpp165
-rw-r--r--test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp160
-rw-r--r--test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp259
-rw-r--r--test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp157
-rw-r--r--test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp275
-rw-r--r--test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp89
-rw-r--r--test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp71
-rw-r--r--test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp81
-rw-r--r--test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp77
-rw-r--r--test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp87
-rw-r--r--test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp192
-rw-r--r--test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp93
-rw-r--r--test/std/containers/associative/map/map.modifiers/try.emplace.pass.cpp189
14 files changed, 1958 insertions, 0 deletions
diff --git a/test/std/containers/associative/map/map.modifiers/clear.pass.cpp b/test/std/containers/associative/map/map.modifiers/clear.pass.cpp
new file mode 100644
index 000000000000..c37499df307a
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/clear.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// void clear();
+
+#include <map>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ {
+ typedef std::map<int, double> M;
+ typedef std::pair<int, double> P;
+ P ar[] =
+ {
+ P(1, 1.5),
+ P(2, 2.5),
+ P(3, 3.5),
+ P(4, 4.5),
+ P(5, 5.5),
+ P(6, 6.5),
+ P(7, 7.5),
+ P(8, 8.5),
+ };
+ M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
+ assert(m.size() == 8);
+ m.clear();
+ assert(m.size() == 0);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef std::pair<int, double> P;
+ P ar[] =
+ {
+ P(1, 1.5),
+ P(2, 2.5),
+ P(3, 3.5),
+ P(4, 4.5),
+ P(5, 5.5),
+ P(6, 6.5),
+ P(7, 7.5),
+ P(8, 8.5),
+ };
+ M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
+ assert(m.size() == 8);
+ m.clear();
+ assert(m.size() == 0);
+ }
+#endif
+}
diff --git a/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp b/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp
new file mode 100644
index 000000000000..81846c6647c6
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp
@@ -0,0 +1,165 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// template <class... Args>
+// pair<iterator, bool> emplace(Args&&... args);
+
+#include <map>
+#include <cassert>
+#include <tuple>
+
+#include "../../../Emplaceable.h"
+#include "DefaultOnly.h"
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef std::map<int, DefaultOnly> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ assert(DefaultOnly::count == 0);
+ R r = m.emplace();
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 0);
+ assert(m.begin()->second == DefaultOnly());
+ assert(DefaultOnly::count == 1);
+ r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
+ std::forward_as_tuple());
+ assert(r.second);
+ assert(r.first == next(m.begin()));
+ assert(m.size() == 2);
+ assert(next(m.begin())->first == 1);
+ assert(next(m.begin())->second == DefaultOnly());
+ assert(DefaultOnly::count == 2);
+ r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
+ std::forward_as_tuple());
+ assert(!r.second);
+ assert(r.first == next(m.begin()));
+ assert(m.size() == 2);
+ assert(next(m.begin())->first == 1);
+ assert(next(m.begin())->second == DefaultOnly());
+ assert(DefaultOnly::count == 2);
+ }
+ assert(DefaultOnly::count == 0);
+ {
+ typedef std::map<int, Emplaceable> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2),
+ std::forward_as_tuple());
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == Emplaceable());
+ r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
+ std::forward_as_tuple(2, 3.5));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == Emplaceable(2, 3.5));
+ r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
+ std::forward_as_tuple(2, 3.5));
+ assert(!r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == Emplaceable(2, 3.5));
+ }
+ {
+ typedef std::map<int, double> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r = m.emplace(M::value_type(2, 3.5));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 3.5);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ assert(DefaultOnly::count == 0);
+ R r = m.emplace();
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 0);
+ assert(m.begin()->second == DefaultOnly());
+ assert(DefaultOnly::count == 1);
+ r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
+ std::forward_as_tuple());
+ assert(r.second);
+ assert(r.first == next(m.begin()));
+ assert(m.size() == 2);
+ assert(next(m.begin())->first == 1);
+ assert(next(m.begin())->second == DefaultOnly());
+ assert(DefaultOnly::count == 2);
+ r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
+ std::forward_as_tuple());
+ assert(!r.second);
+ assert(r.first == next(m.begin()));
+ assert(m.size() == 2);
+ assert(next(m.begin())->first == 1);
+ assert(next(m.begin())->second == DefaultOnly());
+ assert(DefaultOnly::count == 2);
+ }
+ assert(DefaultOnly::count == 0);
+ {
+ typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2),
+ std::forward_as_tuple());
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == Emplaceable());
+ r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
+ std::forward_as_tuple(2, 3.5));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == Emplaceable(2, 3.5));
+ r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1),
+ std::forward_as_tuple(2, 3.5));
+ assert(!r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == Emplaceable(2, 3.5));
+ }
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r = m.emplace(M::value_type(2, 3.5));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 3.5);
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp b/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp
new file mode 100644
index 000000000000..15f74b17e786
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp
@@ -0,0 +1,160 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// template <class... Args>
+// iterator emplace_hint(const_iterator position, Args&&... args);
+
+#include <map>
+#include <cassert>
+
+#include "../../../Emplaceable.h"
+#include "DefaultOnly.h"
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef std::map<int, DefaultOnly> M;
+ typedef M::iterator R;
+ M m;
+ assert(DefaultOnly::count == 0);
+ R r = m.emplace_hint(m.end());
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 0);
+ assert(m.begin()->second == DefaultOnly());
+ assert(DefaultOnly::count == 1);
+ r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple());
+ assert(r == next(m.begin()));
+ assert(m.size() == 2);
+ assert(next(m.begin())->first == 1);
+ assert(next(m.begin())->second == DefaultOnly());
+ assert(DefaultOnly::count == 2);
+ r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple());
+ assert(r == next(m.begin()));
+ assert(m.size() == 2);
+ assert(next(m.begin())->first == 1);
+ assert(next(m.begin())->second == DefaultOnly());
+ assert(DefaultOnly::count == 2);
+ }
+ assert(DefaultOnly::count == 0);
+ {
+ typedef std::map<int, Emplaceable> M;
+ typedef M::iterator R;
+ M m;
+ R r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(2),
+ std::forward_as_tuple());
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == Emplaceable());
+ r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple(2, 3.5));
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == Emplaceable(2, 3.5));
+ r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple(2, 3.5));
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == Emplaceable(2, 3.5));
+ }
+ {
+ typedef std::map<int, double> M;
+ typedef M::iterator R;
+ M m;
+ R r = m.emplace_hint(m.end(), M::value_type(2, 3.5));
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 3.5);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M;
+ typedef M::iterator R;
+ M m;
+ assert(DefaultOnly::count == 0);
+ R r = m.emplace_hint(m.end());
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 0);
+ assert(m.begin()->second == DefaultOnly());
+ assert(DefaultOnly::count == 1);
+ r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple());
+ assert(r == next(m.begin()));
+ assert(m.size() == 2);
+ assert(next(m.begin())->first == 1);
+ assert(next(m.begin())->second == DefaultOnly());
+ assert(DefaultOnly::count == 2);
+ r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple());
+ assert(r == next(m.begin()));
+ assert(m.size() == 2);
+ assert(next(m.begin())->first == 1);
+ assert(next(m.begin())->second == DefaultOnly());
+ assert(DefaultOnly::count == 2);
+ }
+ assert(DefaultOnly::count == 0);
+ {
+ typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M;
+ typedef M::iterator R;
+ M m;
+ R r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(2),
+ std::forward_as_tuple());
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == Emplaceable());
+ r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple(2, 3.5));
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == Emplaceable(2, 3.5));
+ r = m.emplace_hint(m.end(), std::piecewise_construct,
+ std::forward_as_tuple(1),
+ std::forward_as_tuple(2, 3.5));
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == Emplaceable(2, 3.5));
+ }
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef M::iterator R;
+ M m;
+ R r = m.emplace_hint(m.end(), M::value_type(2, 3.5));
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 3.5);
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp b/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp
new file mode 100644
index 000000000000..15c5ce041b68
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp
@@ -0,0 +1,259 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// iterator erase(const_iterator position);
+
+#include <map>
+#include <cassert>
+
+#include "min_allocator.h"
+
+struct TemplateConstructor
+{
+ template<typename T>
+ TemplateConstructor (const T&) {}
+};
+
+bool operator<(const TemplateConstructor&, const TemplateConstructor&) { return false; }
+
+int main()
+{
+ {
+ typedef std::map<int, double> M;
+ typedef std::pair<int, double> P;
+ typedef M::iterator I;
+ P ar[] =
+ {
+ P(1, 1.5),
+ P(2, 2.5),
+ P(3, 3.5),
+ P(4, 4.5),
+ P(5, 5.5),
+ P(6, 6.5),
+ P(7, 7.5),
+ P(8, 8.5),
+ };
+ M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
+ assert(m.size() == 8);
+ I i = m.erase(next(m.cbegin(), 3));
+ assert(m.size() == 7);
+ assert(i == next(m.begin(), 3));
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1.5);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 2.5);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 3.5);
+ assert(next(m.begin(), 3)->first == 5);
+ assert(next(m.begin(), 3)->second == 5.5);
+ assert(next(m.begin(), 4)->first == 6);
+ assert(next(m.begin(), 4)->second == 6.5);
+ assert(next(m.begin(), 5)->first == 7);
+ assert(next(m.begin(), 5)->second == 7.5);
+ assert(next(m.begin(), 6)->first == 8);
+ assert(next(m.begin(), 6)->second == 8.5);
+
+ i = m.erase(next(m.cbegin(), 0));
+ assert(m.size() == 6);
+ assert(i == m.begin());
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 3);
+ assert(next(m.begin())->second == 3.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+ assert(next(m.begin(), 5)->first == 8);
+ assert(next(m.begin(), 5)->second == 8.5);
+
+ i = m.erase(next(m.cbegin(), 5));
+ assert(m.size() == 5);
+ assert(i == m.end());
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 3);
+ assert(next(m.begin())->second == 3.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+
+ i = m.erase(next(m.cbegin(), 1));
+ assert(m.size() == 4);
+ assert(i == next(m.begin()));
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+ assert(next(m.begin(), 2)->first == 6);
+ assert(next(m.begin(), 2)->second == 6.5);
+ assert(next(m.begin(), 3)->first == 7);
+ assert(next(m.begin(), 3)->second == 7.5);
+
+ i = m.erase(next(m.cbegin(), 2));
+ assert(m.size() == 3);
+ assert(i == next(m.begin(), 2));
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+ assert(next(m.begin(), 2)->first == 7);
+ assert(next(m.begin(), 2)->second == 7.5);
+
+ i = m.erase(next(m.cbegin(), 2));
+ assert(m.size() == 2);
+ assert(i == next(m.begin(), 2));
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+
+ i = m.erase(next(m.cbegin(), 0));
+ assert(m.size() == 1);
+ assert(i == next(m.begin(), 0));
+ assert(m.begin()->first == 5);
+ assert(m.begin()->second == 5.5);
+
+ i = m.erase(m.cbegin());
+ assert(m.size() == 0);
+ assert(i == m.begin());
+ assert(i == m.end());
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef std::pair<int, double> P;
+ typedef M::iterator I;
+ P ar[] =
+ {
+ P(1, 1.5),
+ P(2, 2.5),
+ P(3, 3.5),
+ P(4, 4.5),
+ P(5, 5.5),
+ P(6, 6.5),
+ P(7, 7.5),
+ P(8, 8.5),
+ };
+ M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
+ assert(m.size() == 8);
+ I i = m.erase(next(m.cbegin(), 3));
+ assert(m.size() == 7);
+ assert(i == next(m.begin(), 3));
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1.5);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 2.5);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 3.5);
+ assert(next(m.begin(), 3)->first == 5);
+ assert(next(m.begin(), 3)->second == 5.5);
+ assert(next(m.begin(), 4)->first == 6);
+ assert(next(m.begin(), 4)->second == 6.5);
+ assert(next(m.begin(), 5)->first == 7);
+ assert(next(m.begin(), 5)->second == 7.5);
+ assert(next(m.begin(), 6)->first == 8);
+ assert(next(m.begin(), 6)->second == 8.5);
+
+ i = m.erase(next(m.cbegin(), 0));
+ assert(m.size() == 6);
+ assert(i == m.begin());
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 3);
+ assert(next(m.begin())->second == 3.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+ assert(next(m.begin(), 5)->first == 8);
+ assert(next(m.begin(), 5)->second == 8.5);
+
+ i = m.erase(next(m.cbegin(), 5));
+ assert(m.size() == 5);
+ assert(i == m.end());
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 3);
+ assert(next(m.begin())->second == 3.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+
+ i = m.erase(next(m.cbegin(), 1));
+ assert(m.size() == 4);
+ assert(i == next(m.begin()));
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+ assert(next(m.begin(), 2)->first == 6);
+ assert(next(m.begin(), 2)->second == 6.5);
+ assert(next(m.begin(), 3)->first == 7);
+ assert(next(m.begin(), 3)->second == 7.5);
+
+ i = m.erase(next(m.cbegin(), 2));
+ assert(m.size() == 3);
+ assert(i == next(m.begin(), 2));
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+ assert(next(m.begin(), 2)->first == 7);
+ assert(next(m.begin(), 2)->second == 7.5);
+
+ i = m.erase(next(m.cbegin(), 2));
+ assert(m.size() == 2);
+ assert(i == next(m.begin(), 2));
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+
+ i = m.erase(next(m.cbegin(), 0));
+ assert(m.size() == 1);
+ assert(i == next(m.begin(), 0));
+ assert(m.begin()->first == 5);
+ assert(m.begin()->second == 5.5);
+
+ i = m.erase(m.cbegin());
+ assert(m.size() == 0);
+ assert(i == m.begin());
+ assert(i == m.end());
+ }
+#endif
+#if __cplusplus >= 201402L
+ {
+ // This is LWG #2059
+ typedef TemplateConstructor T;
+ typedef std::map<T, int> C;
+ typedef C::iterator I;
+
+ C c;
+ T a{0};
+ I it = c.find(a);
+ if (it != c.end())
+ c.erase(it);
+ }
+#endif
+}
diff --git a/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp b/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp
new file mode 100644
index 000000000000..1b49956d8a5a
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp
@@ -0,0 +1,157 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// iterator erase(const_iterator first, const_iterator last);
+
+#include <map>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ {
+ typedef std::map<int, double> M;
+ typedef std::pair<int, double> P;
+ typedef M::iterator I;
+ P ar[] =
+ {
+ P(1, 1.5),
+ P(2, 2.5),
+ P(3, 3.5),
+ P(4, 4.5),
+ P(5, 5.5),
+ P(6, 6.5),
+ P(7, 7.5),
+ P(8, 8.5),
+ };
+ M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
+ assert(m.size() == 8);
+ I i = m.erase(m.cbegin(), m.cbegin());
+ assert(m.size() == 8);
+ assert(i == m.begin());
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1.5);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 2.5);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 3.5);
+ assert(next(m.begin(), 3)->first == 4);
+ assert(next(m.begin(), 3)->second == 4.5);
+ assert(next(m.begin(), 4)->first == 5);
+ assert(next(m.begin(), 4)->second == 5.5);
+ assert(next(m.begin(), 5)->first == 6);
+ assert(next(m.begin(), 5)->second == 6.5);
+ assert(next(m.begin(), 6)->first == 7);
+ assert(next(m.begin(), 6)->second == 7.5);
+ assert(next(m.begin(), 7)->first == 8);
+ assert(next(m.begin(), 7)->second == 8.5);
+
+ i = m.erase(m.cbegin(), next(m.cbegin(), 2));
+ assert(m.size() == 6);
+ assert(i == m.begin());
+ assert(next(m.begin(), 0)->first == 3);
+ assert(next(m.begin(), 0)->second == 3.5);
+ assert(next(m.begin(), 1)->first == 4);
+ assert(next(m.begin(), 1)->second == 4.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+ assert(next(m.begin(), 5)->first == 8);
+ assert(next(m.begin(), 5)->second == 8.5);
+
+ i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 6));
+ assert(m.size() == 2);
+ assert(i == next(m.begin(), 2));
+ assert(next(m.begin(), 0)->first == 3);
+ assert(next(m.begin(), 0)->second == 3.5);
+ assert(next(m.begin(), 1)->first == 4);
+ assert(next(m.begin(), 1)->second == 4.5);
+
+ i = m.erase(m.cbegin(), m.cend());
+ assert(m.size() == 0);
+ assert(i == m.begin());
+ assert(i == m.end());
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef std::pair<int, double> P;
+ typedef M::iterator I;
+ P ar[] =
+ {
+ P(1, 1.5),
+ P(2, 2.5),
+ P(3, 3.5),
+ P(4, 4.5),
+ P(5, 5.5),
+ P(6, 6.5),
+ P(7, 7.5),
+ P(8, 8.5),
+ };
+ M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
+ assert(m.size() == 8);
+ I i = m.erase(m.cbegin(), m.cbegin());
+ assert(m.size() == 8);
+ assert(i == m.begin());
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1.5);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 2.5);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 3.5);
+ assert(next(m.begin(), 3)->first == 4);
+ assert(next(m.begin(), 3)->second == 4.5);
+ assert(next(m.begin(), 4)->first == 5);
+ assert(next(m.begin(), 4)->second == 5.5);
+ assert(next(m.begin(), 5)->first == 6);
+ assert(next(m.begin(), 5)->second == 6.5);
+ assert(next(m.begin(), 6)->first == 7);
+ assert(next(m.begin(), 6)->second == 7.5);
+ assert(next(m.begin(), 7)->first == 8);
+ assert(next(m.begin(), 7)->second == 8.5);
+
+ i = m.erase(m.cbegin(), next(m.cbegin(), 2));
+ assert(m.size() == 6);
+ assert(i == m.begin());
+ assert(next(m.begin(), 0)->first == 3);
+ assert(next(m.begin(), 0)->second == 3.5);
+ assert(next(m.begin(), 1)->first == 4);
+ assert(next(m.begin(), 1)->second == 4.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+ assert(next(m.begin(), 5)->first == 8);
+ assert(next(m.begin(), 5)->second == 8.5);
+
+ i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 6));
+ assert(m.size() == 2);
+ assert(i == next(m.begin(), 2));
+ assert(next(m.begin(), 0)->first == 3);
+ assert(next(m.begin(), 0)->second == 3.5);
+ assert(next(m.begin(), 1)->first == 4);
+ assert(next(m.begin(), 1)->second == 4.5);
+
+ i = m.erase(m.cbegin(), m.cend());
+ assert(m.size() == 0);
+ assert(i == m.begin());
+ assert(i == m.end());
+ }
+#endif
+}
diff --git a/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp b/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp
new file mode 100644
index 000000000000..e41f5129140e
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp
@@ -0,0 +1,275 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// size_type erase(const key_type& k);
+
+#include <map>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ {
+ typedef std::map<int, double> M;
+ typedef std::pair<int, double> P;
+ typedef M::size_type R;
+ P ar[] =
+ {
+ P(1, 1.5),
+ P(2, 2.5),
+ P(3, 3.5),
+ P(4, 4.5),
+ P(5, 5.5),
+ P(6, 6.5),
+ P(7, 7.5),
+ P(8, 8.5),
+ };
+ M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
+ assert(m.size() == 8);
+ R s = m.erase(9);
+ assert(s == 0);
+ assert(m.size() == 8);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1.5);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 2.5);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 3.5);
+ assert(next(m.begin(), 3)->first == 4);
+ assert(next(m.begin(), 3)->second == 4.5);
+ assert(next(m.begin(), 4)->first == 5);
+ assert(next(m.begin(), 4)->second == 5.5);
+ assert(next(m.begin(), 5)->first == 6);
+ assert(next(m.begin(), 5)->second == 6.5);
+ assert(next(m.begin(), 6)->first == 7);
+ assert(next(m.begin(), 6)->second == 7.5);
+ assert(next(m.begin(), 7)->first == 8);
+ assert(next(m.begin(), 7)->second == 8.5);
+
+ s = m.erase(4);
+ assert(m.size() == 7);
+ assert(s == 1);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1.5);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 2.5);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 3.5);
+ assert(next(m.begin(), 3)->first == 5);
+ assert(next(m.begin(), 3)->second == 5.5);
+ assert(next(m.begin(), 4)->first == 6);
+ assert(next(m.begin(), 4)->second == 6.5);
+ assert(next(m.begin(), 5)->first == 7);
+ assert(next(m.begin(), 5)->second == 7.5);
+ assert(next(m.begin(), 6)->first == 8);
+ assert(next(m.begin(), 6)->second == 8.5);
+
+ s = m.erase(1);
+ assert(m.size() == 6);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 3);
+ assert(next(m.begin())->second == 3.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+ assert(next(m.begin(), 5)->first == 8);
+ assert(next(m.begin(), 5)->second == 8.5);
+
+ s = m.erase(8);
+ assert(m.size() == 5);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 3);
+ assert(next(m.begin())->second == 3.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+
+ s = m.erase(3);
+ assert(m.size() == 4);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+ assert(next(m.begin(), 2)->first == 6);
+ assert(next(m.begin(), 2)->second == 6.5);
+ assert(next(m.begin(), 3)->first == 7);
+ assert(next(m.begin(), 3)->second == 7.5);
+
+ s = m.erase(6);
+ assert(m.size() == 3);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+ assert(next(m.begin(), 2)->first == 7);
+ assert(next(m.begin(), 2)->second == 7.5);
+
+ s = m.erase(7);
+ assert(m.size() == 2);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+
+ s = m.erase(2);
+ assert(m.size() == 1);
+ assert(s == 1);
+ assert(m.begin()->first == 5);
+ assert(m.begin()->second == 5.5);
+
+ s = m.erase(5);
+ assert(m.size() == 0);
+ assert(s == 1);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef std::pair<int, double> P;
+ typedef M::size_type R;
+ P ar[] =
+ {
+ P(1, 1.5),
+ P(2, 2.5),
+ P(3, 3.5),
+ P(4, 4.5),
+ P(5, 5.5),
+ P(6, 6.5),
+ P(7, 7.5),
+ P(8, 8.5),
+ };
+ M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
+ assert(m.size() == 8);
+ R s = m.erase(9);
+ assert(s == 0);
+ assert(m.size() == 8);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1.5);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 2.5);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 3.5);
+ assert(next(m.begin(), 3)->first == 4);
+ assert(next(m.begin(), 3)->second == 4.5);
+ assert(next(m.begin(), 4)->first == 5);
+ assert(next(m.begin(), 4)->second == 5.5);
+ assert(next(m.begin(), 5)->first == 6);
+ assert(next(m.begin(), 5)->second == 6.5);
+ assert(next(m.begin(), 6)->first == 7);
+ assert(next(m.begin(), 6)->second == 7.5);
+ assert(next(m.begin(), 7)->first == 8);
+ assert(next(m.begin(), 7)->second == 8.5);
+
+ s = m.erase(4);
+ assert(m.size() == 7);
+ assert(s == 1);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1.5);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 2.5);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 3.5);
+ assert(next(m.begin(), 3)->first == 5);
+ assert(next(m.begin(), 3)->second == 5.5);
+ assert(next(m.begin(), 4)->first == 6);
+ assert(next(m.begin(), 4)->second == 6.5);
+ assert(next(m.begin(), 5)->first == 7);
+ assert(next(m.begin(), 5)->second == 7.5);
+ assert(next(m.begin(), 6)->first == 8);
+ assert(next(m.begin(), 6)->second == 8.5);
+
+ s = m.erase(1);
+ assert(m.size() == 6);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 3);
+ assert(next(m.begin())->second == 3.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+ assert(next(m.begin(), 5)->first == 8);
+ assert(next(m.begin(), 5)->second == 8.5);
+
+ s = m.erase(8);
+ assert(m.size() == 5);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 3);
+ assert(next(m.begin())->second == 3.5);
+ assert(next(m.begin(), 2)->first == 5);
+ assert(next(m.begin(), 2)->second == 5.5);
+ assert(next(m.begin(), 3)->first == 6);
+ assert(next(m.begin(), 3)->second == 6.5);
+ assert(next(m.begin(), 4)->first == 7);
+ assert(next(m.begin(), 4)->second == 7.5);
+
+ s = m.erase(3);
+ assert(m.size() == 4);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+ assert(next(m.begin(), 2)->first == 6);
+ assert(next(m.begin(), 2)->second == 6.5);
+ assert(next(m.begin(), 3)->first == 7);
+ assert(next(m.begin(), 3)->second == 7.5);
+
+ s = m.erase(6);
+ assert(m.size() == 3);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+ assert(next(m.begin(), 2)->first == 7);
+ assert(next(m.begin(), 2)->second == 7.5);
+
+ s = m.erase(7);
+ assert(m.size() == 2);
+ assert(s == 1);
+ assert(m.begin()->first == 2);
+ assert(m.begin()->second == 2.5);
+ assert(next(m.begin())->first == 5);
+ assert(next(m.begin())->second == 5.5);
+
+ s = m.erase(2);
+ assert(m.size() == 1);
+ assert(s == 1);
+ assert(m.begin()->first == 5);
+ assert(m.begin()->second == 5.5);
+
+ s = m.erase(5);
+ assert(m.size() == 0);
+ assert(s == 1);
+ }
+#endif
+}
diff --git a/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp
new file mode 100644
index 000000000000..3d28242fd322
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// pair<iterator, bool> insert(const value_type& v);
+
+#include <map>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ {
+ typedef std::map<int, double> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r = m.insert(M::value_type(2, 2.5));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(r.first->first == 2);
+ assert(r.first->second == 2.5);
+
+ r = m.insert(M::value_type(1, 1.5));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(r.first->first == 1);
+ assert(r.first->second == 1.5);
+
+ r = m.insert(M::value_type(3, 3.5));
+ assert(r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r.first->first == 3);
+ assert(r.first->second == 3.5);
+
+ r = m.insert(M::value_type(3, 3.5));
+ assert(!r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r.first->first == 3);
+ assert(r.first->second == 3.5);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r = m.insert(M::value_type(2, 2.5));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(r.first->first == 2);
+ assert(r.first->second == 2.5);
+
+ r = m.insert(M::value_type(1, 1.5));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(r.first->first == 1);
+ assert(r.first->second == 1.5);
+
+ r = m.insert(M::value_type(3, 3.5));
+ assert(r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r.first->first == 3);
+ assert(r.first->second == 3.5);
+
+ r = m.insert(M::value_type(3, 3.5));
+ assert(!r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r.first->first == 3);
+ assert(r.first->second == 3.5);
+ }
+#endif
+}
diff --git a/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp
new file mode 100644
index 000000000000..ab325ed45bfc
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// void insert(initializer_list<value_type> il);
+
+#include <map>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+ {
+ typedef std::pair<const int, double> V;
+ std::map<int, double> m =
+ {
+ {1, 1},
+ {1, 1.5},
+ {1, 2},
+ {3, 1},
+ {3, 1.5},
+ {3, 2}
+ };
+ m.insert({
+ {2, 1},
+ {2, 1.5},
+ {2, 2},
+ });
+ assert(m.size() == 3);
+ assert(distance(m.begin(), m.end()) == 3);
+ assert(*m.begin() == V(1, 1));
+ assert(*next(m.begin()) == V(2, 1));
+ assert(*next(m.begin(), 2) == V(3, 1));
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::pair<const int, double> V;
+ std::map<int, double, std::less<int>, min_allocator<V>> m =
+ {
+ {1, 1},
+ {1, 1.5},
+ {1, 2},
+ {3, 1},
+ {3, 1.5},
+ {3, 2}
+ };
+ m.insert({
+ {2, 1},
+ {2, 1.5},
+ {2, 2},
+ });
+ assert(m.size() == 3);
+ assert(distance(m.begin(), m.end()) == 3);
+ assert(*m.begin() == V(1, 1));
+ assert(*next(m.begin()) == V(2, 1));
+ assert(*next(m.begin(), 2) == V(3, 1));
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+}
diff --git a/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp
new file mode 100644
index 000000000000..278db4631a8c
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// iterator insert(const_iterator position, const value_type& v);
+
+#include <map>
+#include <cassert>
+
+#include "min_allocator.h"
+
+int main()
+{
+ {
+ typedef std::map<int, double> M;
+ typedef M::iterator R;
+ M m;
+ R r = m.insert(m.end(), M::value_type(2, 2.5));
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(r->first == 2);
+ assert(r->second == 2.5);
+
+ r = m.insert(m.end(), M::value_type(1, 1.5));
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(r->first == 1);
+ assert(r->second == 1.5);
+
+ r = m.insert(m.end(), M::value_type(3, 3.5));
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r->first == 3);
+ assert(r->second == 3.5);
+
+ r = m.insert(m.end(), M::value_type(3, 3.5));
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r->first == 3);
+ assert(r->second == 3.5);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef M::iterator R;
+ M m;
+ R r = m.insert(m.end(), M::value_type(2, 2.5));
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(r->first == 2);
+ assert(r->second == 2.5);
+
+ r = m.insert(m.end(), M::value_type(1, 1.5));
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(r->first == 1);
+ assert(r->second == 1.5);
+
+ r = m.insert(m.end(), M::value_type(3, 3.5));
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r->first == 3);
+ assert(r->second == 3.5);
+
+ r = m.insert(m.end(), M::value_type(3, 3.5));
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r->first == 3);
+ assert(r->second == 3.5);
+ }
+#endif
+}
diff --git a/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp
new file mode 100644
index 000000000000..964738b4a68a
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// template <class InputIterator>
+// void insert(InputIterator first, InputIterator last);
+
+#include <map>
+#include <cassert>
+
+#include "test_iterators.h"
+#include "min_allocator.h"
+
+int main()
+{
+ {
+ typedef std::map<int, double> M;
+ typedef std::pair<int, double> P;
+ P ar[] =
+ {
+ P(1, 1),
+ P(1, 1.5),
+ P(1, 2),
+ P(2, 1),
+ P(2, 1.5),
+ P(2, 2),
+ P(3, 1),
+ P(3, 1.5),
+ P(3, 2),
+ };
+ M m;
+ m.insert(input_iterator<P*>(ar), input_iterator<P*>(ar + sizeof(ar)/sizeof(ar[0])));
+ assert(m.size() == 3);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 1);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 1);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
+ typedef std::pair<int, double> P;
+ P ar[] =
+ {
+ P(1, 1),
+ P(1, 1.5),
+ P(1, 2),
+ P(2, 1),
+ P(2, 1.5),
+ P(2, 2),
+ P(3, 1),
+ P(3, 1.5),
+ P(3, 2),
+ };
+ M m;
+ m.insert(input_iterator<P*>(ar), input_iterator<P*>(ar + sizeof(ar)/sizeof(ar[0])));
+ assert(m.size() == 3);
+ assert(m.begin()->first == 1);
+ assert(m.begin()->second == 1);
+ assert(next(m.begin())->first == 2);
+ assert(next(m.begin())->second == 1);
+ assert(next(m.begin(), 2)->first == 3);
+ assert(next(m.begin(), 2)->second == 1);
+ }
+#endif
+}
diff --git a/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp
new file mode 100644
index 000000000000..42b41fd7b867
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp
@@ -0,0 +1,87 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// template <class P>
+// iterator insert(const_iterator position, P&& p);
+
+#include <map>
+#include <cassert>
+
+#include "MoveOnly.h"
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef std::map<int, MoveOnly> M;
+ typedef std::pair<int, MoveOnly> P;
+ typedef M::iterator R;
+ M m;
+ R r = m.insert(m.end(), P(2, 2));
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(r->first == 2);
+ assert(r->second == 2);
+
+ r = m.insert(m.end(), P(1, 1));
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(r->first == 1);
+ assert(r->second == 1);
+
+ r = m.insert(m.end(), P(3, 3));
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r->first == 3);
+ assert(r->second == 3);
+
+ r = m.insert(m.end(), P(3, 3));
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r->first == 3);
+ assert(r->second == 3);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
+ typedef std::pair<int, MoveOnly> P;
+ typedef M::iterator R;
+ M m;
+ R r = m.insert(m.end(), P(2, 2));
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(r->first == 2);
+ assert(r->second == 2);
+
+ r = m.insert(m.end(), P(1, 1));
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(r->first == 1);
+ assert(r->second == 1);
+
+ r = m.insert(m.end(), P(3, 3));
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r->first == 3);
+ assert(r->second == 3);
+
+ r = m.insert(m.end(), P(3, 3));
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r->first == 3);
+ assert(r->second == 3);
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp
new file mode 100644
index 000000000000..484ed06247d1
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp
@@ -0,0 +1,192 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: c++03, c++11, c++14
+
+// <map>
+
+// class map
+
+// template <class M>
+// pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
+// template <class M>
+// pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
+// template <class M>
+// iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
+// template <class M>
+// iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
+
+#include <__config>
+#include <map>
+#include <cassert>
+#include <tuple>
+
+#include <iostream>
+
+class Moveable
+{
+ Moveable(const Moveable&);
+ Moveable& operator=(const Moveable&);
+
+ int int_;
+ double double_;
+public:
+ Moveable() : int_(0), double_(0) {}
+ Moveable(int i, double d) : int_(i), double_(d) {}
+ Moveable(Moveable&& x)
+ : int_(x.int_), double_(x.double_)
+ {x.int_ = -1; x.double_ = -1;}
+ Moveable& operator=(Moveable&& x)
+ {int_ = x.int_; x.int_ = -1;
+ double_ = x.double_; x.double_ = -1;
+ return *this;
+ }
+
+ bool operator==(const Moveable& x) const
+ {return int_ == x.int_ && double_ == x.double_;}
+ bool operator<(const Moveable& x) const
+ {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);}
+
+ int get() const {return int_;}
+ bool moved() const {return int_ == -1;}
+};
+
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ { // pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
+ typedef std::map<int, Moveable> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r;
+ for ( int i = 0; i < 20; i += 2 )
+ m.emplace ( i, Moveable(i, (double) i));
+ assert(m.size() == 10);
+
+ for (int i=0; i < 20; i += 2)
+ {
+ Moveable mv(i+1, i+1);
+ r = m.insert_or_assign(i, std::move(mv));
+ assert(m.size() == 10);
+ assert(!r.second); // was not inserted
+ assert(mv.moved()); // was moved from
+ assert(r.first->first == i); // key
+ assert(r.first->second.get() == i+1); // value
+ }
+
+ Moveable mv1(5, 5.0);
+ r = m.insert_or_assign(-1, std::move(mv1));
+ assert(m.size() == 11);
+ assert(r.second); // was inserted
+ assert(mv1.moved()); // was moved from
+ assert(r.first->first == -1); // key
+ assert(r.first->second.get() == 5); // value
+
+ Moveable mv2(9, 9.0);
+ r = m.insert_or_assign(3, std::move(mv2));
+ assert(m.size() == 12);
+ assert(r.second); // was inserted
+ assert(mv2.moved()); // was moved from
+ assert(r.first->first == 3); // key
+ assert(r.first->second.get() == 9); // value
+
+ Moveable mv3(-1, 5.0);
+ r = m.insert_or_assign(117, std::move(mv3));
+ assert(m.size() == 13);
+ assert(r.second); // was inserted
+ assert(mv3.moved()); // was moved from
+ assert(r.first->first == 117); // key
+ assert(r.first->second.get() == -1); // value
+ }
+ { // pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
+ typedef std::map<Moveable, Moveable> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r;
+ for ( int i = 0; i < 20; i += 2 )
+ m.emplace ( Moveable(i, (double) i), Moveable(i+1, (double) i+1));
+ assert(m.size() == 10);
+
+ Moveable mvkey1(2, 2.0);
+ Moveable mv1(4, 4.0);
+ r = m.insert_or_assign(std::move(mvkey1), std::move(mv1));
+ assert(m.size() == 10);
+ assert(!r.second); // was not inserted
+ assert(!mvkey1.moved()); // was not moved from
+ assert(mv1.moved()); // was moved from
+ assert(r.first->first == mvkey1); // key
+ assert(r.first->second.get() == 4); // value
+
+ Moveable mvkey2(3, 3.0);
+ Moveable mv2(5, 5.0);
+ r = m.try_emplace(std::move(mvkey2), std::move(mv2));
+ assert(m.size() == 11);
+ assert(r.second); // was inserted
+ assert(mv2.moved()); // was moved from
+ assert(mvkey2.moved()); // was moved from
+ assert(r.first->first.get() == 3); // key
+ assert(r.first->second.get() == 5); // value
+ }
+ { // iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
+ typedef std::map<int, Moveable> M;
+ M m;
+ M::iterator r;
+ for ( int i = 0; i < 20; i += 2 )
+ m.emplace ( i, Moveable(i, (double) i));
+ assert(m.size() == 10);
+ M::const_iterator it = m.find(2);
+
+ Moveable mv1(3, 3.0);
+ r = m.insert_or_assign(it, 2, std::move(mv1));
+ assert(m.size() == 10);
+ assert(mv1.moved()); // was moved from
+ assert(r->first == 2); // key
+ assert(r->second.get() == 3); // value
+
+ Moveable mv2(5, 5.0);
+ r = m.insert_or_assign(it, 3, std::move(mv2));
+ assert(m.size() == 11);
+ assert(mv2.moved()); // was moved from
+ assert(r->first == 3); // key
+ assert(r->second.get() == 5); // value
+ }
+ { // iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
+ typedef std::map<Moveable, Moveable> M;
+ M m;
+ M::iterator r;
+ for ( int i = 0; i < 20; i += 2 )
+ m.emplace ( Moveable(i, (double) i), Moveable(i+1, (double) i+1));
+ assert(m.size() == 10);
+ M::const_iterator it = std::next(m.cbegin());
+
+ Moveable mvkey1(2, 2.0);
+ Moveable mv1(4, 4.0);
+ r = m.insert_or_assign(it, std::move(mvkey1), std::move(mv1));
+ assert(m.size() == 10);
+ assert(mv1.moved()); // was moved from
+ assert(!mvkey1.moved()); // was not moved from
+ assert(r->first == mvkey1); // key
+ assert(r->second.get() == 4); // value
+
+ Moveable mvkey2(3, 3.0);
+ Moveable mv2(5, 5.0);
+ r = m.insert_or_assign(it, std::move(mvkey2), std::move(mv2));
+ assert(m.size() == 11);
+ assert(mv2.moved()); // was moved from
+ assert(mvkey2.moved()); // was moved from
+ assert(r->first.get() == 3); // key
+ assert(r->second.get() == 5); // value
+ }
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+} \ No newline at end of file
diff --git a/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp
new file mode 100644
index 000000000000..a9d3277e6d94
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp
@@ -0,0 +1,93 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// template <class P>
+// pair<iterator, bool> insert(P&& p);
+
+#include <map>
+#include <cassert>
+
+#include "MoveOnly.h"
+#include "min_allocator.h"
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ {
+ typedef std::map<int, MoveOnly> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r = m.insert(M::value_type(2, 2));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(r.first->first == 2);
+ assert(r.first->second == 2);
+
+ r = m.insert(M::value_type(1, 1));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(r.first->first == 1);
+ assert(r.first->second == 1);
+
+ r = m.insert(M::value_type(3, 3));
+ assert(r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r.first->first == 3);
+ assert(r.first->second == 3);
+
+ r = m.insert(M::value_type(3, 3));
+ assert(!r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r.first->first == 3);
+ assert(r.first->second == 3);
+ }
+#if __cplusplus >= 201103L
+ {
+ typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r = m.insert(M::value_type(2, 2));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(r.first->first == 2);
+ assert(r.first->second == 2);
+
+ r = m.insert(M::value_type(1, 1));
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(r.first->first == 1);
+ assert(r.first->second == 1);
+
+ r = m.insert(M::value_type(3, 3));
+ assert(r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r.first->first == 3);
+ assert(r.first->second == 3);
+
+ r = m.insert(M::value_type(3, 3));
+ assert(!r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(r.first->first == 3);
+ assert(r.first->second == 3);
+ }
+#endif
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}
diff --git a/test/std/containers/associative/map/map.modifiers/try.emplace.pass.cpp b/test/std/containers/associative/map/map.modifiers/try.emplace.pass.cpp
new file mode 100644
index 000000000000..8e0dd7577bbd
--- /dev/null
+++ b/test/std/containers/associative/map/map.modifiers/try.emplace.pass.cpp
@@ -0,0 +1,189 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: c++03, c++11, c++14
+
+// <map>
+
+// class map
+
+// template <class... Args>
+// pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
+// template <class... Args>
+// pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
+// template <class... Args>
+// iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
+// template <class... Args>
+// iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
+
+#include <__config>
+#include <map>
+#include <cassert>
+#include <tuple>
+
+class Moveable
+{
+ Moveable(const Moveable&);
+ Moveable& operator=(const Moveable&);
+
+ int int_;
+ double double_;
+public:
+ Moveable() : int_(0), double_(0) {}
+ Moveable(int i, double d) : int_(i), double_(d) {}
+ Moveable(Moveable&& x)
+ : int_(x.int_), double_(x.double_)
+ {x.int_ = -1; x.double_ = -1;}
+ Moveable& operator=(Moveable&& x)
+ {int_ = x.int_; x.int_ = -1;
+ double_ = x.double_; x.double_ = -1;
+ return *this;
+ }
+
+ bool operator==(const Moveable& x) const
+ {return int_ == x.int_ && double_ == x.double_;}
+ bool operator<(const Moveable& x) const
+ {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);}
+
+ int get() const {return int_;}
+ bool moved() const {return int_ == -1;}
+};
+
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ { // pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
+ typedef std::map<int, Moveable> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r;
+ for (int i = 0; i < 20; i += 2)
+ m.emplace (i, Moveable(i, (double) i));
+ assert(m.size() == 10);
+
+ Moveable mv1(3, 3.0);
+ for (int i=0; i < 20; i += 2)
+ {
+ r = m.try_emplace(i, std::move(mv1));
+ assert(m.size() == 10);
+ assert(!r.second); // was not inserted
+ assert(!mv1.moved()); // was not moved from
+ assert(r.first->first == i); // key
+ }
+
+ r = m.try_emplace(-1, std::move(mv1));
+ assert(m.size() == 11);
+ assert(r.second); // was inserted
+ assert(mv1.moved()); // was moved from
+ assert(r.first->first == -1); // key
+ assert(r.first->second.get() == 3); // value
+
+ Moveable mv2(5, 3.0);
+ r = m.try_emplace(5, std::move(mv2));
+ assert(m.size() == 12);
+ assert(r.second); // was inserted
+ assert(mv2.moved()); // was moved from
+ assert(r.first->first == 5); // key
+ assert(r.first->second.get() == 5); // value
+
+ Moveable mv3(-1, 3.0);
+ r = m.try_emplace(117, std::move(mv2));
+ assert(m.size() == 13);
+ assert(r.second); // was inserted
+ assert(mv2.moved()); // was moved from
+ assert(r.first->first == 117); // key
+ assert(r.first->second.get() == -1); // value
+ }
+
+ { // pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
+ typedef std::map<Moveable, Moveable> M;
+ typedef std::pair<M::iterator, bool> R;
+ M m;
+ R r;
+ for ( int i = 0; i < 20; i += 2 )
+ m.emplace ( Moveable(i, (double) i), Moveable(i+1, (double) i+1));
+ assert(m.size() == 10);
+
+ Moveable mvkey1(2, 2.0);
+ Moveable mv1(4, 4.0);
+ r = m.try_emplace(std::move(mvkey1), std::move(mv1));
+ assert(m.size() == 10);
+ assert(!r.second); // was not inserted
+ assert(!mv1.moved()); // was not moved from
+ assert(!mvkey1.moved()); // was not moved from
+ assert(r.first->first == mvkey1); // key
+
+ Moveable mvkey2(3, 3.0);
+ r = m.try_emplace(std::move(mvkey2), std::move(mv1));
+ assert(m.size() == 11);
+ assert(r.second); // was inserted
+ assert(mv1.moved()); // was moved from
+ assert(mvkey2.moved()); // was moved from
+ assert(r.first->first.get() == 3); // key
+ assert(r.first->second.get() == 4); // value
+ }
+
+ { // iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
+ typedef std::map<int, Moveable> M;
+ M m;
+ M::iterator r;
+ for ( int i = 0; i < 20; i += 2 )
+ m.try_emplace ( i, Moveable(i, (double) i));
+ assert(m.size() == 10);
+ M::const_iterator it = m.find(2);
+
+ Moveable mv1(3, 3.0);
+ for (int i=0; i < 20; i += 2)
+ {
+ r = m.try_emplace(it, i, std::move(mv1));
+ assert(m.size() == 10);
+ assert(!mv1.moved()); // was not moved from
+ assert(r->first == i); // key
+ assert(r->second.get() == i); // value
+ }
+
+ r = m.try_emplace(it, 3, std::move(mv1));
+ assert(m.size() == 11);
+ assert(mv1.moved()); // was moved from
+ assert(r->first == 3); // key
+ assert(r->second.get() == 3); // value
+ }
+
+ { // iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
+ typedef std::map<Moveable, Moveable> M;
+ M m;
+ M::iterator r;
+ for ( int i = 0; i < 20; i += 2 )
+ m.emplace ( Moveable(i, (double) i), Moveable(i+1, (double) i+1));
+ assert(m.size() == 10);
+ M::const_iterator it = std::next(m.cbegin());
+
+ Moveable mvkey1(2, 2.0);
+ Moveable mv1(4, 4.0);
+ r = m.try_emplace(it, std::move(mvkey1), std::move(mv1));
+ assert(m.size() == 10);
+ assert(!mv1.moved()); // was not moved from
+ assert(!mvkey1.moved()); // was not moved from
+ assert(r->first == mvkey1); // key
+
+ Moveable mvkey2(3, 3.0);
+ r = m.try_emplace(it, std::move(mvkey2), std::move(mv1));
+ assert(m.size() == 11);
+ assert(mv1.moved()); // was moved from
+ assert(mvkey2.moved()); // was moved from
+ assert(r->first.get() == 3); // key
+ assert(r->second.get() == 4); // value
+ }
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+}