forked from boostorg/unordered
Add a test that unnecessary copies aren't made of objects inserted.
Make the exception tests track the allocator usage. Speed up the exception tests a bit. [SVN r3490]
This commit is contained in:
49
test/unordered/unnecessary_copy_tests.cpp
Normal file
49
test/unordered/unnecessary_copy_tests.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
// Copyright 2006 Daniel James.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
struct count_copies
|
||||
{
|
||||
static int count;
|
||||
count_copies() { ++count; }
|
||||
count_copies(count_copies const& x) { ++count; }
|
||||
private:
|
||||
count_copies& operator=(count_copies const&);
|
||||
};
|
||||
|
||||
std::size_t hash_value(count_copies const& x) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool operator==(count_copies const& x, count_copies const& y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int count_copies::count;
|
||||
|
||||
template <class T>
|
||||
void unnecessary_copy_test(T*)
|
||||
{
|
||||
count_copies::count = 0;
|
||||
T x;
|
||||
typename T::value_type a;
|
||||
BOOST_TEST(count_copies::count == 1);
|
||||
x.insert(a);
|
||||
BOOST_TEST(count_copies::count == 2);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
unnecessary_copy_test((boost::unordered_set<count_copies>*) 0);
|
||||
unnecessary_copy_test((boost::unordered_multiset<count_copies>*) 0);
|
||||
unnecessary_copy_test((boost::unordered_map<int, count_copies>*) 0);
|
||||
unnecessary_copy_test((boost::unordered_multimap<int, count_copies>*) 0);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user