Add emplace tests for multiset/unordered_multiset.

This patch adds tests to ensure that multiset/unordered_multiset's emplace
method correctly constructs the elements without any intervening
constructions.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@346743 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2018-11-13 06:30:36 +00:00
parent 3870a97d86
commit 16a8e7ec37
3 changed files with 46 additions and 1 deletions

View File

@@ -23,4 +23,5 @@
int main() int main()
{ {
testMultisetInsert<TCT::multiset<> >(); testMultisetInsert<TCT::multiset<> >();
testMultisetEmplace<TCT::multiset<> >();
} }

View File

@@ -344,11 +344,54 @@ void testMultisetInsert()
{ {
CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&"); CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
Container c; Container c;
ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(3) }; ValueTp ValueList[] = { ValueTp(1), ValueTp(2) , ValueTp(1) };
cc->expect<ValueTp&>(3); cc->expect<ValueTp&>(3);
c.insert(std::begin(ValueList), std::end(ValueList)); c.insert(std::begin(ValueList), std::end(ValueList));
assert(!cc->unchecked()); assert(!cc->unchecked());
} }
} }
template <class Container>
void testMultisetEmplace()
{
typedef typename Container::value_type ValueTp;
typedef Container C;
typedef std::pair<typename C::iterator, bool> R;
ConstructController* cc = getConstructController();
cc->reset();
{
CHECKPOINT("Testing C::emplace(const value_type&)");
Container c;
const ValueTp v(42);
cc->expect<const ValueTp&>();
c.emplace(v);
assert(!cc->unchecked());
}
{
CHECKPOINT("Testing C::emplace(value_type&)");
Container c;
ValueTp v(42);
cc->expect<ValueTp&>();
c.emplace(v);
assert(!cc->unchecked());
}
{
CHECKPOINT("Testing C::emplace(value_type&&)");
Container c;
ValueTp v(42);
cc->expect<ValueTp&&>();
c.emplace(std::move(v));
assert(!cc->unchecked());
}
{
CHECKPOINT("Testing C::emplace(const value_type&&)");
Container c;
const ValueTp v(42);
cc->expect<const ValueTp&&>();
c.emplace(std::move(v));
assert(!cc->unchecked());
}
}
#endif #endif

View File

@@ -22,4 +22,5 @@
int main() int main()
{ {
testMultisetInsert<TCT::unordered_multiset<> >(); testMultisetInsert<TCT::unordered_multiset<> >();
testMultisetEmplace<TCT::unordered_multiset<> >();
} }