[libcxx] r329541 - [test] Fix Container::insert(value_type const&) tests
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 8 14:57:35 PDT 2018
Author: ericwf
Date: Sun Apr 8 14:57:35 2018
New Revision: 329541
URL: http://llvm.org/viewvc/llvm-project?rev=329541&view=rev
Log:
[test] Fix Container::insert(value_type const&) tests
Patch from Joe Loser.
Several unit tests meaning to test the behavior of lvalue insertion incorrectly
pass rvalues. Fixes bug PR # 27394
Reviewed as https://reviews.llvm.org/D44411
Modified:
libcxx/trunk/test/std/containers/associative/multiset/insert_cv.pass.cpp
libcxx/trunk/test/std/containers/associative/set/insert_cv.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp
Modified: libcxx/trunk/test/std/containers/associative/multiset/insert_cv.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/multiset/insert_cv.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/associative/multiset/insert_cv.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/associative/multiset/insert_cv.pass.cpp Sun Apr 8 14:57:35 2018
@@ -18,56 +18,44 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_cv_test()
+{
+ typedef Container M;
+ typedef typename M::iterator R;
+ typedef typename M::value_type VT;
+ M m;
+ const VT v1(2);
+ R r = m.insert(v1);
+ assert(r == m.begin());
+ assert(m.size() == 1);
+ assert(*r == 2);
+
+ const VT v2(1);
+ r = m.insert(v2);
+ assert(r == m.begin());
+ assert(m.size() == 2);
+ assert(*r == 1);
+
+ const VT v3(3);
+ r = m.insert(v3);
+ assert(r == prev(m.end()));
+ assert(m.size() == 3);
+ assert(*r == 3);
+
+ r = m.insert(v3);
+ assert(r == prev(m.end()));
+ assert(m.size() == 4);
+ assert(*r == 3);
+}
+
int main()
{
- {
- typedef std::multiset<int> M;
- typedef M::iterator R;
- M m;
- R r = m.insert(M::value_type(2));
- assert(r == m.begin());
- assert(m.size() == 1);
- assert(*r == 2);
-
- r = m.insert(M::value_type(1));
- assert(r == m.begin());
- assert(m.size() == 2);
- assert(*r == 1);
-
- r = m.insert(M::value_type(3));
- assert(r == prev(m.end()));
- assert(m.size() == 3);
- assert(*r == 3);
-
- r = m.insert(M::value_type(3));
- assert(r == prev(m.end()));
- assert(m.size() == 4);
- assert(*r == 3);
- }
+ do_insert_cv_test<std::multiset<int> >();
#if TEST_STD_VER >= 11
{
typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
- typedef M::iterator R;
- M m;
- R r = m.insert(M::value_type(2));
- assert(r == m.begin());
- assert(m.size() == 1);
- assert(*r == 2);
-
- r = m.insert(M::value_type(1));
- assert(r == m.begin());
- assert(m.size() == 2);
- assert(*r == 1);
-
- r = m.insert(M::value_type(3));
- assert(r == prev(m.end()));
- assert(m.size() == 3);
- assert(*r == 3);
-
- r = m.insert(M::value_type(3));
- assert(r == prev(m.end()));
- assert(m.size() == 4);
- assert(*r == 3);
+ do_insert_cv_test<M>();
}
#endif
}
Modified: libcxx/trunk/test/std/containers/associative/set/insert_cv.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/set/insert_cv.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/associative/set/insert_cv.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/associative/set/insert_cv.pass.cpp Sun Apr 8 14:57:35 2018
@@ -18,64 +18,49 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_cv_test()
+{
+ typedef Container M;
+ typedef std::pair<typename M::iterator, bool> R;
+ typedef typename M::value_type VT;
+ M m;
+
+ const VT v1(2);
+ R r = m.insert(v1);
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 1);
+ assert(*r.first == 2);
+
+ const VT v2(1);
+ r = m.insert(v2);
+ assert(r.second);
+ assert(r.first == m.begin());
+ assert(m.size() == 2);
+ assert(*r.first == 1);
+
+ const VT v3(3);
+ r = m.insert(v3);
+ assert(r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(*r.first == 3);
+
+ r = m.insert(v3);
+ assert(!r.second);
+ assert(r.first == prev(m.end()));
+ assert(m.size() == 3);
+ assert(*r.first == 3);
+}
+
int main()
{
- {
- typedef std::set<int> M;
- typedef std::pair<M::iterator, bool> R;
- M m;
- R r = m.insert(M::value_type(2));
- assert(r.second);
- assert(r.first == m.begin());
- assert(m.size() == 1);
- assert(*r.first == 2);
-
- r = m.insert(M::value_type(1));
- assert(r.second);
- assert(r.first == m.begin());
- assert(m.size() == 2);
- assert(*r.first == 1);
-
- r = m.insert(M::value_type(3));
- assert(r.second);
- assert(r.first == prev(m.end()));
- assert(m.size() == 3);
- assert(*r.first == 3);
-
- r = m.insert(M::value_type(3));
- assert(!r.second);
- assert(r.first == prev(m.end()));
- assert(m.size() == 3);
- assert(*r.first == 3);
- }
+ do_insert_cv_test<std::set<int> >();
#if TEST_STD_VER >= 11
{
typedef std::set<int, std::less<int>, min_allocator<int>> M;
- typedef std::pair<M::iterator, bool> R;
- M m;
- R r = m.insert(M::value_type(2));
- assert(r.second);
- assert(r.first == m.begin());
- assert(m.size() == 1);
- assert(*r.first == 2);
-
- r = m.insert(M::value_type(1));
- assert(r.second);
- assert(r.first == m.begin());
- assert(m.size() == 2);
- assert(*r.first == 1);
-
- r = m.insert(M::value_type(3));
- assert(r.second);
- assert(r.first == prev(m.end()));
- assert(m.size() == 3);
- assert(*r.first == 3);
-
- r = m.insert(M::value_type(3));
- assert(!r.second);
- assert(r.first == prev(m.end()));
- assert(m.size() == 3);
- assert(*r.first == 3);
+ do_insert_cv_test<M>();
}
#endif
}
Modified: libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_const_lvalue.pass.cpp Sun Apr 8 14:57:35 2018
@@ -37,28 +37,29 @@ void do_insert_cv_test()
assert(r.first->first == 2.5);
assert(r.first->second == 2);
- r = m.insert(VT(2.5, 3)); // test rvalue insertion works in C++03
+ const VT v2(2.5, 3);
+ r = m.insert(v2);
assert(!r.second);
assert(m.size() == 1);
assert(r.first->first == 2.5);
assert(r.first->second == 2);
- const VT v2(1.5, 1);
- r = m.insert(v2);
+ const VT v3(1.5, 1);
+ r = m.insert(v3);
assert(r.second);
assert(m.size() == 2);
assert(r.first->first == 1.5);
assert(r.first->second == 1);
- const VT v3(3.5, 3);
- r = m.insert(v3);
+ const VT v4(3.5, 3);
+ r = m.insert(v4);
assert(r.second);
assert(m.size() == 3);
assert(r.first->first == 3.5);
assert(r.first->second == 3);
- const VT v4(3.5, 4);
- r = m.insert(v4);
+ const VT v5(3.5, 4);
+ r = m.insert(v5);
assert(!r.second);
assert(m.size() == 3);
assert(r.first->first == 3.5);
Modified: libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.pass.cpp Sun Apr 8 14:57:35 2018
@@ -24,61 +24,48 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_hint_const_lvalue_test()
+{
+ typedef Container C;
+ typedef typename C::iterator R;
+ typedef typename C::value_type VT;
+ C c;
+ typename C::const_iterator e = c.end();
+ const VT v1(3.5, 3);
+ R r = c.insert(e, v1);
+ assert(c.size() == 1);
+ assert(r->first == 3.5);
+ assert(r->second == 3);
+
+ const VT v2(3.5, 4);
+ r = c.insert(c.end(), v2);
+ assert(c.size() == 1);
+ assert(r->first == 3.5);
+ assert(r->second == 3);
+
+ const VT v3(4.5, 4);
+ r = c.insert(c.end(), v3);
+ assert(c.size() == 2);
+ assert(r->first == 4.5);
+ assert(r->second == 4);
+
+ const VT v4(5.5, 4);
+ r = c.insert(c.end(), v4);
+ assert(c.size() == 3);
+ assert(r->first == 5.5);
+ assert(r->second == 4);
+}
+
int main()
{
- {
- typedef std::unordered_map<double, int> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- C::const_iterator e = c.end();
- R r = c.insert(e, P(3.5, 3));
- assert(c.size() == 1);
- assert(r->first == 3.5);
- assert(r->second == 3);
-
- r = c.insert(c.end(), P(3.5, 4));
- assert(c.size() == 1);
- assert(r->first == 3.5);
- assert(r->second == 3);
-
- r = c.insert(c.end(), P(4.5, 4));
- assert(c.size() == 2);
- assert(r->first == 4.5);
- assert(r->second == 4);
-
- r = c.insert(c.end(), P(5.5, 4));
- assert(c.size() == 3);
- assert(r->first == 5.5);
- assert(r->second == 4);
- }
+ do_insert_hint_const_lvalue_test<std::unordered_map<double, int> >();
#if TEST_STD_VER >= 11
{
typedef std::unordered_map<double, int, std::hash<double>, std::equal_to<double>,
min_allocator<std::pair<const double, int>>> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- C::const_iterator e = c.end();
- R r = c.insert(e, P(3.5, 3));
- assert(c.size() == 1);
- assert(r->first == 3.5);
- assert(r->second == 3);
-
- r = c.insert(c.end(), P(3.5, 4));
- assert(c.size() == 1);
- assert(r->first == 3.5);
- assert(r->second == 3);
-
- r = c.insert(c.end(), P(4.5, 4));
- assert(c.size() == 2);
- assert(r->first == 4.5);
- assert(r->second == 4);
-
- r = c.insert(c.end(), P(5.5, 4));
- assert(c.size() == 3);
- assert(r->first == 5.5);
- assert(r->second == 4);
+
+ do_insert_hint_const_lvalue_test<C>();
}
#endif
#if _LIBCPP_DEBUG >= 1
Modified: libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp Sun Apr 8 14:57:35 2018
@@ -20,59 +20,46 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_const_lvalue_test()
+{
+ typedef Container C;
+ typedef typename C::iterator R;
+ typedef typename C::value_type VT;
+ C c;
+ const VT v1(3.5, 3);
+ R r = c.insert(v1);
+ assert(c.size() == 1);
+ assert(r->first == 3.5);
+ assert(r->second == 3);
+
+ const VT v2(3.5, 4);
+ r = c.insert(v2);
+ assert(c.size() == 2);
+ assert(r->first == 3.5);
+ assert(r->second == 4);
+
+ const VT v3(4.5, 4);
+ r = c.insert(v3);
+ assert(c.size() == 3);
+ assert(r->first == 4.5);
+ assert(r->second == 4);
+
+ const VT v4(5.5, 4);
+ r = c.insert(v4);
+ assert(c.size() == 4);
+ assert(r->first == 5.5);
+ assert(r->second == 4);
+}
+
int main()
{
- {
- typedef std::unordered_multimap<double, int> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- R r = c.insert(P(3.5, 3));
- assert(c.size() == 1);
- assert(r->first == 3.5);
- assert(r->second == 3);
-
- r = c.insert(P(3.5, 4));
- assert(c.size() == 2);
- assert(r->first == 3.5);
- assert(r->second == 4);
-
- r = c.insert(P(4.5, 4));
- assert(c.size() == 3);
- assert(r->first == 4.5);
- assert(r->second == 4);
-
- r = c.insert(P(5.5, 4));
- assert(c.size() == 4);
- assert(r->first == 5.5);
- assert(r->second == 4);
- }
+ do_insert_const_lvalue_test<std::unordered_multimap<double, int> >();
#if TEST_STD_VER >= 11
{
typedef std::unordered_multimap<double, int, std::hash<double>, std::equal_to<double>,
min_allocator<std::pair<const double, int>>> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- R r = c.insert(P(3.5, 3));
- assert(c.size() == 1);
- assert(r->first == 3.5);
- assert(r->second == 3);
-
- r = c.insert(P(3.5, 4));
- assert(c.size() == 2);
- assert(r->first == 3.5);
- assert(r->second == 4);
-
- r = c.insert(P(4.5, 4));
- assert(c.size() == 3);
- assert(r->first == 4.5);
- assert(r->second == 4);
-
- r = c.insert(P(5.5, 4));
- assert(c.size() == 4);
- assert(r->first == 5.5);
- assert(r->second == 4);
+ do_insert_const_lvalue_test<C>();
}
#endif
}
Modified: libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp Sun Apr 8 14:57:35 2018
@@ -24,61 +24,47 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_const_lvalue_test()
+{
+ typedef Container C;
+ typedef typename C::iterator R;
+ typedef typename C::value_type VT;
+ C c;
+ typename C::const_iterator e = c.end();
+ const VT v1(3.5, 3);
+ R r = c.insert(e, v1);
+ assert(c.size() == 1);
+ assert(r->first == 3.5);
+ assert(r->second == 3);
+
+ const VT v2(3.5, 4);
+ r = c.insert(c.end(), v2);
+ assert(c.size() == 2);
+ assert(r->first == 3.5);
+ assert(r->second == 4);
+
+ const VT v3(4.5, 4);
+ r = c.insert(c.end(), v3);
+ assert(c.size() == 3);
+ assert(r->first == 4.5);
+ assert(r->second == 4);
+
+ const VT v4(5.5, 4);
+ r = c.insert(c.end(), v4);
+ assert(c.size() == 4);
+ assert(r->first == 5.5);
+ assert(r->second == 4);
+}
+
int main()
{
- {
- typedef std::unordered_multimap<double, int> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- C::const_iterator e = c.end();
- R r = c.insert(e, P(3.5, 3));
- assert(c.size() == 1);
- assert(r->first == 3.5);
- assert(r->second == 3);
-
- r = c.insert(c.end(), P(3.5, 4));
- assert(c.size() == 2);
- assert(r->first == 3.5);
- assert(r->second == 4);
-
- r = c.insert(c.end(), P(4.5, 4));
- assert(c.size() == 3);
- assert(r->first == 4.5);
- assert(r->second == 4);
-
- r = c.insert(c.end(), P(5.5, 4));
- assert(c.size() == 4);
- assert(r->first == 5.5);
- assert(r->second == 4);
- }
+ do_insert_const_lvalue_test<std::unordered_multimap<double, int> >();
#if TEST_STD_VER >= 11
{
typedef std::unordered_multimap<double, int, std::hash<double>, std::equal_to<double>,
min_allocator<std::pair<const double, int>>> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- C::const_iterator e = c.end();
- R r = c.insert(e, P(3.5, 3));
- assert(c.size() == 1);
- assert(r->first == 3.5);
- assert(r->second == 3);
-
- r = c.insert(c.end(), P(3.5, 4));
- assert(c.size() == 2);
- assert(r->first == 3.5);
- assert(r->second == 4);
-
- r = c.insert(c.end(), P(4.5, 4));
- assert(c.size() == 3);
- assert(r->first == 4.5);
- assert(r->second == 4);
-
- r = c.insert(c.end(), P(5.5, 4));
- assert(c.size() == 4);
- assert(r->first == 5.5);
- assert(r->second == 4);
+ do_insert_const_lvalue_test<C>();
}
#endif
#if _LIBCPP_DEBUG >= 1
Modified: libcxx/trunk/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp Sun Apr 8 14:57:35 2018
@@ -20,51 +20,41 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_const_lvalue_test()
+{
+ typedef Container C;
+ typedef typename C::iterator R;
+ typedef typename C::value_type VT;
+ C c;
+ const VT v1(3.5);
+ R r = c.insert(v1);
+ assert(c.size() == 1);
+ assert(*r == 3.5);
+
+ r = c.insert(v1);
+ assert(c.size() == 2);
+ assert(*r == 3.5);
+
+ const VT v2(4.5);
+ r = c.insert(v2);
+ assert(c.size() == 3);
+ assert(*r == 4.5);
+
+ const VT v3(5.5);
+ r = c.insert(v3);
+ assert(c.size() == 4);
+ assert(*r == 5.5);
+}
+
int main()
{
- {
- typedef std::unordered_multiset<double> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- R r = c.insert(P(3.5));
- assert(c.size() == 1);
- assert(*r == 3.5);
-
- r = c.insert(P(3.5));
- assert(c.size() == 2);
- assert(*r == 3.5);
-
- r = c.insert(P(4.5));
- assert(c.size() == 3);
- assert(*r == 4.5);
-
- r = c.insert(P(5.5));
- assert(c.size() == 4);
- assert(*r == 5.5);
- }
+ do_insert_const_lvalue_test<std::unordered_multiset<double> >();
#if TEST_STD_VER >= 11
{
typedef std::unordered_multiset<double, std::hash<double>,
- std::equal_to<double>, min_allocator<double>> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- R r = c.insert(P(3.5));
- assert(c.size() == 1);
- assert(*r == 3.5);
-
- r = c.insert(P(3.5));
- assert(c.size() == 2);
- assert(*r == 3.5);
-
- r = c.insert(P(4.5));
- assert(c.size() == 3);
- assert(*r == 4.5);
-
- r = c.insert(P(5.5));
- assert(c.size() == 4);
- assert(*r == 5.5);
+ std::equal_to<double>, min_allocator<double>> C;
+ do_insert_const_lvalue_test<C>();
}
#endif
}
Modified: libcxx/trunk/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp Sun Apr 8 14:57:35 2018
@@ -24,53 +24,42 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_hint_const_lvalue_test()
+{
+ typedef Container C;
+ typedef typename C::iterator R;
+ typedef typename C::value_type VT;
+ C c;
+ typename C::const_iterator e = c.end();
+ const VT v1(3.5);
+ R r = c.insert(e, v1);
+ assert(c.size() == 1);
+ assert(*r == 3.5);
+
+ r = c.insert(c.end(), v1);
+ assert(c.size() == 2);
+ assert(*r == 3.5);
+
+ const VT v2(4.5);
+ r = c.insert(c.end(), v2);
+ assert(c.size() == 3);
+ assert(*r == 4.5);
+
+ const VT v3(5.5);
+ r = c.insert(c.end(), v3);
+ assert(c.size() == 4);
+ assert(*r == 5.5);
+}
+
int main()
{
- {
- typedef std::unordered_multiset<double> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- C::const_iterator e = c.end();
- R r = c.insert(e, P(3.5));
- assert(c.size() == 1);
- assert(*r == 3.5);
-
- r = c.insert(c.end(), P(3.5));
- assert(c.size() == 2);
- assert(*r == 3.5);
-
- r = c.insert(c.end(), P(4.5));
- assert(c.size() == 3);
- assert(*r == 4.5);
-
- r = c.insert(c.end(), P(5.5));
- assert(c.size() == 4);
- assert(*r == 5.5);
- }
+ do_insert_hint_const_lvalue_test<std::unordered_multiset<double> >();
#if TEST_STD_VER >= 11
{
typedef std::unordered_multiset<double, std::hash<double>,
- std::equal_to<double>, min_allocator<double>> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- C::const_iterator e = c.end();
- R r = c.insert(e, P(3.5));
- assert(c.size() == 1);
- assert(*r == 3.5);
-
- r = c.insert(c.end(), P(3.5));
- assert(c.size() == 2);
- assert(*r == 3.5);
-
- r = c.insert(c.end(), P(4.5));
- assert(c.size() == 3);
- assert(*r == 4.5);
-
- r = c.insert(c.end(), P(5.5));
- assert(c.size() == 4);
- assert(*r == 5.5);
+ std::equal_to<double>, min_allocator<double>> C;
+ do_insert_hint_const_lvalue_test<C>();
}
#endif
#if _LIBCPP_DEBUG >= 1
Modified: libcxx/trunk/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp Sun Apr 8 14:57:35 2018
@@ -20,59 +20,45 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_const_lvalue_test()
+{
+ typedef Container C;
+ typedef std::pair<typename C::iterator, bool> R;
+ typedef typename C::value_type VT;
+ C c;
+ const VT v1(3.5);
+ R r = c.insert(v1);
+ assert(c.size() == 1);
+ assert(*r.first == 3.5);
+ assert(r.second);
+
+ r = c.insert(v1);
+ assert(c.size() == 1);
+ assert(*r.first == 3.5);
+ assert(!r.second);
+
+ const VT v2(4.5);
+ r = c.insert(v2);
+ assert(c.size() == 2);
+ assert(*r.first == 4.5);
+ assert(r.second);
+
+ const VT v3(5.5);
+ r = c.insert(v3);
+ assert(c.size() == 3);
+ assert(*r.first == 5.5);
+ assert(r.second);
+}
+
int main()
{
- {
- typedef std::unordered_set<double> C;
- typedef std::pair<C::iterator, bool> R;
- typedef C::value_type P;
- C c;
- R r = c.insert(P(3.5));
- assert(c.size() == 1);
- assert(*r.first == 3.5);
- assert(r.second);
-
- r = c.insert(P(3.5));
- assert(c.size() == 1);
- assert(*r.first == 3.5);
- assert(!r.second);
-
- r = c.insert(P(4.5));
- assert(c.size() == 2);
- assert(*r.first == 4.5);
- assert(r.second);
-
- r = c.insert(P(5.5));
- assert(c.size() == 3);
- assert(*r.first == 5.5);
- assert(r.second);
- }
+ do_insert_const_lvalue_test<std::unordered_set<double> >();
#if TEST_STD_VER >= 11
{
typedef std::unordered_set<double, std::hash<double>,
std::equal_to<double>, min_allocator<double>> C;
- typedef std::pair<C::iterator, bool> R;
- typedef C::value_type P;
- C c;
- R r = c.insert(P(3.5));
- assert(c.size() == 1);
- assert(*r.first == 3.5);
- assert(r.second);
-
- r = c.insert(P(3.5));
- assert(c.size() == 1);
- assert(*r.first == 3.5);
- assert(!r.second);
-
- r = c.insert(P(4.5));
- assert(c.size() == 2);
- assert(*r.first == 4.5);
- assert(r.second);
-
- r = c.insert(P(5.5));
- assert(c.size() == 3);
- assert(*r.first == 5.5);
- assert(r.second);
+ do_insert_const_lvalue_test<C>();
}
#endif
}
Modified: libcxx/trunk/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp?rev=329541&r1=329540&r2=329541&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp Sun Apr 8 14:57:35 2018
@@ -24,53 +24,42 @@
#include "min_allocator.h"
+template<class Container>
+void do_insert_hint_const_lvalue_test()
+{
+ typedef Container C;
+ typedef typename C::iterator R;
+ typedef typename C::value_type VT;
+ C c;
+ typename C::const_iterator e = c.end();
+ const VT v1(3.5);
+ R r = c.insert(e, v1);
+ assert(c.size() == 1);
+ assert(*r == 3.5);
+
+ r = c.insert(e, v1);
+ assert(c.size() == 1);
+ assert(*r == 3.5);
+
+ const VT v2(4.5);
+ r = c.insert(e, v2);
+ assert(c.size() == 2);
+ assert(*r == 4.5);
+
+ const VT v3(5.5);
+ r = c.insert(e, v3);
+ assert(c.size() == 3);
+ assert(*r == 5.5);
+}
+
int main()
{
- {
- typedef std::unordered_set<double> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- C::const_iterator e = c.end();
- R r = c.insert(e, P(3.5));
- assert(c.size() == 1);
- assert(*r == 3.5);
-
- r = c.insert(e, P(3.5));
- assert(c.size() == 1);
- assert(*r == 3.5);
-
- r = c.insert(e, P(4.5));
- assert(c.size() == 2);
- assert(*r == 4.5);
-
- r = c.insert(e, P(5.5));
- assert(c.size() == 3);
- assert(*r == 5.5);
- }
+ do_insert_hint_const_lvalue_test<std::unordered_set<double> >();
#if TEST_STD_VER >= 11
{
typedef std::unordered_set<double, std::hash<double>,
std::equal_to<double>, min_allocator<double>> C;
- typedef C::iterator R;
- typedef C::value_type P;
- C c;
- C::const_iterator e = c.end();
- R r = c.insert(e, P(3.5));
- assert(c.size() == 1);
- assert(*r == 3.5);
-
- r = c.insert(e, P(3.5));
- assert(c.size() == 1);
- assert(*r == 3.5);
-
- r = c.insert(e, P(4.5));
- assert(c.size() == 2);
- assert(*r == 4.5);
-
- r = c.insert(e, P(5.5));
- assert(c.size() == 3);
- assert(*r == 5.5);
+ do_insert_hint_const_lvalue_test<C>();
}
#endif
#if _LIBCPP_DEBUG >= 1
More information about the cfe-commits
mailing list