|
Boost-Commit : |
From: daniel_james_at_[hidden]
Date: 2008-04-05 07:39:38
Author: danieljames
Date: 2008-04-05 07:39:38 EDT (Sat, 05 Apr 2008)
New Revision: 44047
URL: http://svn.boost.org/trac/boost/changeset/44047
Log:
New constructors with allocators.
Text files modified:
branches/unordered/trunk/boost/unordered/detail/hash_table_impl.hpp | 18 ++++++++++++++++++
branches/unordered/trunk/boost/unordered_map.hpp | 23 +++++++++++++++++++++++
branches/unordered/trunk/boost/unordered_set.hpp | 24 ++++++++++++++++++++++++
branches/unordered/trunk/libs/unordered/test/exception/constructor_exception_tests.cpp | 10 +++++++++-
branches/unordered/trunk/libs/unordered/test/exception/copy_exception_tests.cpp | 16 +++++++++++++++-
branches/unordered/trunk/libs/unordered/test/unordered/constructor_tests.cpp | 11 +++++++++++
branches/unordered/trunk/libs/unordered/test/unordered/copy_tests.cpp | 24 ++++++++++++++++++++++++
7 files changed, 124 insertions(+), 2 deletions(-)
Modified: branches/unordered/trunk/boost/unordered/detail/hash_table_impl.hpp
==============================================================================
--- branches/unordered/trunk/boost/unordered/detail/hash_table_impl.hpp (original)
+++ branches/unordered/trunk/boost/unordered/detail/hash_table_impl.hpp 2008-04-05 07:39:38 EDT (Sat, 05 Apr 2008)
@@ -1080,6 +1080,7 @@
// This can throw, but BOOST_UNORDERED_TABLE_DATA's destructor will clean up.
insert(i, j);
}
+
// Copy Construct
BOOST_UNORDERED_TABLE(BOOST_UNORDERED_TABLE const& x)
@@ -1096,6 +1097,23 @@
copy_buckets(x.data_, data_, current_functions());
}
+ // Copy Construct with allocator
+
+ BOOST_UNORDERED_TABLE(BOOST_UNORDERED_TABLE const& x,
+ value_allocator const& a)
+ : func1_(x.current_functions()), // throws
+ func2_(x.current_functions()), // throws
+ func_(&BOOST_UNORDERED_TABLE::func1_), // no throw
+ mlf_(x.mlf_), // no throw
+ data_(x.min_buckets_for_size(x.size()), a)
+ {
+ calculate_max_load(); // no throw
+
+ // This can throw, but BOOST_UNORDERED_TABLE_DATA's destructor will clean
+ // up.
+ copy_buckets(x.data_, data_, current_functions());
+ }
+
// Assign
//
// basic exception safety, if copy_functions of reserver throws
Modified: branches/unordered/trunk/boost/unordered_map.hpp
==============================================================================
--- branches/unordered/trunk/boost/unordered_map.hpp (original)
+++ branches/unordered/trunk/boost/unordered_map.hpp 2008-04-05 07:39:38 EDT (Sat, 05 Apr 2008)
@@ -71,6 +71,18 @@
{
}
+ // TODO: Should this be explicit?
+ unordered_map(allocator_type const& a)
+ : base(boost::unordered_detail::default_initial_bucket_count,
+ hasher(), key_equal(), a)
+ {
+ }
+
+ unordered_map(unordered_map const& other, allocator_type const& a)
+ : base(other.base, a)
+ {
+ }
+
template <class InputIterator>
unordered_map(InputIterator f, InputIterator l)
: base(f, l, boost::unordered_detail::default_initial_bucket_count,
@@ -384,6 +396,17 @@
{
}
+ unordered_multimap(allocator_type const& a)
+ : base(boost::unordered_detail::default_initial_bucket_count,
+ hasher(), key_equal(), a)
+ {
+ }
+
+ unordered_multimap(unordered_multimap const& other, allocator_type const& a)
+ : base(other.base, a)
+ {
+ }
+
template <class InputIterator>
unordered_multimap(InputIterator f, InputIterator l)
: base(f, l, boost::unordered_detail::default_initial_bucket_count,
Modified: branches/unordered/trunk/boost/unordered_set.hpp
==============================================================================
--- branches/unordered/trunk/boost/unordered_set.hpp (original)
+++ branches/unordered/trunk/boost/unordered_set.hpp 2008-04-05 07:39:38 EDT (Sat, 05 Apr 2008)
@@ -69,6 +69,18 @@
{
}
+ // TODO: Should this be explicit?
+ unordered_set(allocator_type const& a)
+ : base(boost::unordered_detail::default_initial_bucket_count,
+ hasher(), key_equal(), a)
+ {
+ }
+
+ unordered_set(unordered_set const& other, allocator_type const& a)
+ : base(other.base, a)
+ {
+ }
+
template <class InputIterator>
unordered_set(InputIterator f, InputIterator l)
: base(f, l, boost::unordered_detail::default_initial_bucket_count,
@@ -352,6 +364,18 @@
{
}
+ // TODO: Should this be explicit?
+ unordered_multiset(allocator_type const& a)
+ : base(boost::unordered_detail::default_initial_bucket_count,
+ hasher(), key_equal(), a)
+ {
+ }
+
+ unordered_multiset(unordered_multiset const& other, allocator_type const& a)
+ : base(other.base, a)
+ {
+ }
+
template <class InputIterator>
unordered_multiset(InputIterator f, InputIterator l)
: base(f, l, boost::unordered_detail::default_initial_bucket_count,
Modified: branches/unordered/trunk/libs/unordered/test/exception/constructor_exception_tests.cpp
==============================================================================
--- branches/unordered/trunk/libs/unordered/test/exception/constructor_exception_tests.cpp (original)
+++ branches/unordered/trunk/libs/unordered/test/exception/constructor_exception_tests.cpp 2008-04-05 07:39:38 EDT (Sat, 05 Apr 2008)
@@ -58,6 +58,14 @@
};
template <class T>
+struct construct_test6 : public objects, test::exception_base
+{
+ void run() const {
+ T x(allocator);
+ }
+};
+
+template <class T>
struct range : public test::exception_base
{
test::random_values<T> values;
@@ -123,7 +131,7 @@
};
RUN_EXCEPTION_TESTS(
- (construct_test1)(construct_test2)(construct_test3)(construct_test4)(construct_test5)
+ (construct_test1)(construct_test2)(construct_test3)(construct_test4)(construct_test5)(construct_test6)
(range_construct_test1)(range_construct_test2)(range_construct_test3)(range_construct_test4)(range_construct_test5)
(input_range_construct_test),
CONTAINER_SEQ)
Modified: branches/unordered/trunk/libs/unordered/test/exception/copy_exception_tests.cpp
==============================================================================
--- branches/unordered/trunk/libs/unordered/test/exception/copy_exception_tests.cpp (original)
+++ branches/unordered/trunk/libs/unordered/test/exception/copy_exception_tests.cpp 2008-04-05 07:39:38 EDT (Sat, 05 Apr 2008)
@@ -44,6 +44,20 @@
}
};
+template <class T>
+struct copy_with_allocator_test : public test::exception_base
+{
+ test::random_values<T> values;
+ T x;
+ test::exception::allocator<test::exception::object> allocator;
+
+ copy_with_allocator_test() : values(100), x(values.begin(), values.end()) {}
+
+ void run() const {
+ T y(x, allocator);
+ }
+};
+
RUN_EXCEPTION_TESTS(
- (copy_test1)(copy_test2)(copy_test3),
+ (copy_test1)(copy_test2)(copy_test3)(copy_with_allocator_test),
CONTAINER_SEQ)
Modified: branches/unordered/trunk/libs/unordered/test/unordered/constructor_tests.cpp
==============================================================================
--- branches/unordered/trunk/libs/unordered/test/unordered/constructor_tests.cpp (original)
+++ branches/unordered/trunk/libs/unordered/test/unordered/constructor_tests.cpp 2008-04-05 07:39:38 EDT (Sat, 05 Apr 2008)
@@ -136,6 +136,17 @@
test::check_container(x, v);
test::check_equivalent_keys(x);
}
+
+ std::cerr<<"Construct 11\n";
+ {
+ test::random_values<T> v(1000, generator);
+ T x(al);
+ BOOST_TEST(x.empty());
+ BOOST_TEST(test::equivalent(x.hash_function(), hf));
+ BOOST_TEST(test::equivalent(x.key_eq(), eq));
+ BOOST_TEST(test::equivalent(x.get_allocator(), al));
+ test::check_equivalent_keys(x);
+ }
}
template <class T>
Modified: branches/unordered/trunk/libs/unordered/test/unordered/copy_tests.cpp
==============================================================================
--- branches/unordered/trunk/libs/unordered/test/unordered/copy_tests.cpp (original)
+++ branches/unordered/trunk/libs/unordered/test/unordered/copy_tests.cpp 2008-04-05 07:39:38 EDT (Sat, 05 Apr 2008)
@@ -70,6 +70,7 @@
BOOST_DEDUCED_TYPENAME T::hasher hf(1);
BOOST_DEDUCED_TYPENAME T::key_equal eq(1);
BOOST_DEDUCED_TYPENAME T::allocator_type al(1);
+ BOOST_DEDUCED_TYPENAME T::allocator_type al2(2);
{
T x(10000, hf, eq, al);
@@ -83,6 +84,17 @@
}
{
+ T x(1000, hf, eq, al);
+ T y(x, al2);
+ BOOST_TEST(y.empty());
+ BOOST_TEST(test::equivalent(y.hash_function(), hf));
+ BOOST_TEST(test::equivalent(y.key_eq(), eq));
+ BOOST_TEST(test::equivalent(y.get_allocator(), al2));
+ BOOST_TEST(x.max_load_factor() == y.max_load_factor());
+ test::check_equivalent_keys(y);
+ }
+
+ {
test::random_values<T> v(1000);
T x(v.begin(), v.end(), 0, hf, eq, al);
@@ -90,6 +102,18 @@
test::unordered_equivalence_tester<T> equivalent(x);
equivalent(y);
test::check_equivalent_keys(y);
+ BOOST_TEST(test::equivalent(y.get_allocator(), al));
+ }
+
+ {
+ test::random_values<T> v(500);
+
+ T x(v.begin(), v.end(), 0, hf, eq, al);
+ T y(x, al2);
+ test::unordered_equivalence_tester<T> equivalent(x);
+ equivalent(y);
+ test::check_equivalent_keys(y);
+ BOOST_TEST(test::equivalent(y.get_allocator(), al2));
}
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk