forked from boostorg/intrusive
Fixed Solaris-gcc errors and added splay trees
[SVN r40429]
This commit is contained in:
1 parent
40835daaba
commit
960f20c3af
30 files changed
+1726
-70
No files matched your search
+57
-18
@@ -18,6 +18,7 @@
|
||||
#include <boost/intrusive/list_hook.hpp>
|
||||
#include <boost/intrusive/slist_hook.hpp>
|
||||
#include <boost/intrusive/unordered_set_hook.hpp>
|
||||
#include <boost/intrusive/splay_set_hook.hpp>
|
||||
#include <boost/intrusive/options.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include "smart_ptr.hpp"
|
||||
@@ -33,16 +34,32 @@ struct set_base_hook_type
|
||||
|
||||
template<class VoidPointer>
|
||||
struct set_auto_base_hook_type
|
||||
{ typedef set_base_hook<link_mode<auto_unlink>, void_pointer<VoidPointer>, tag<my_tag> > type; };
|
||||
{ typedef set_base_hook<link_mode<auto_unlink>, void_pointer<VoidPointer>, tag<my_tag>, optimize_size<true> > type; };
|
||||
|
||||
template<class VoidPointer>
|
||||
struct set_member_hook_type
|
||||
{ typedef set_member_hook<void_pointer<VoidPointer> > type; };
|
||||
{ typedef set_member_hook<void_pointer<VoidPointer>, optimize_size<true> > type; };
|
||||
|
||||
template<class VoidPointer>
|
||||
struct set_auto_member_hook_type
|
||||
{ typedef set_member_hook<link_mode<auto_unlink>, void_pointer<VoidPointer> > type; };
|
||||
|
||||
template<class VoidPointer>
|
||||
struct splay_set_base_hook_type
|
||||
{ typedef splay_set_base_hook<void_pointer<VoidPointer> > type; };
|
||||
|
||||
template<class VoidPointer>
|
||||
struct splay_set_auto_base_hook_type
|
||||
{ typedef splay_set_base_hook<link_mode<auto_unlink>, void_pointer<VoidPointer>, tag<my_tag> > type; };
|
||||
|
||||
template<class VoidPointer>
|
||||
struct splay_set_member_hook_type
|
||||
{ typedef splay_set_member_hook<void_pointer<VoidPointer> > type; };
|
||||
|
||||
template<class VoidPointer>
|
||||
struct splay_set_auto_member_hook_type
|
||||
{ typedef splay_set_member_hook<link_mode<auto_unlink>, void_pointer<VoidPointer> > type; };
|
||||
|
||||
template<class VoidPointer>
|
||||
struct list_base_hook_type
|
||||
{ typedef list_base_hook<void_pointer<VoidPointer> > type; };
|
||||
@@ -95,6 +112,8 @@ template<class VoidPointer, bool ConstantTimeSize>
|
||||
struct testvalue
|
||||
: set_base_hook_type<VoidPointer>::type
|
||||
, set_auto_base_hook_type<VoidPointer>::type
|
||||
, splay_set_base_hook_type<VoidPointer>::type
|
||||
, splay_set_auto_base_hook_type<VoidPointer>::type
|
||||
, list_base_hook_type<VoidPointer>::type
|
||||
, list_auto_base_hook_type<VoidPointer>::type
|
||||
, slist_base_hook_type<VoidPointer>::type
|
||||
@@ -102,30 +121,39 @@ struct testvalue
|
||||
, uset_base_hook_type<VoidPointer>::type
|
||||
, uset_auto_base_hook_type<VoidPointer>::type
|
||||
{
|
||||
typedef typename set_auto_base_hook_type<VoidPointer>::type set_auto_base_hook_t;
|
||||
typedef typename set_base_hook_type<VoidPointer>::type set_base_hook_t;
|
||||
typedef typename set_auto_member_hook_type<VoidPointer>::type set_auto_member_hook_t;
|
||||
typedef typename set_member_hook_type<VoidPointer>::type set_member_hook_t;
|
||||
typedef typename set_auto_base_hook_type<VoidPointer>::type set_auto_base_hook_t;
|
||||
typedef typename set_base_hook_type<VoidPointer>::type set_base_hook_t;
|
||||
typedef typename set_auto_member_hook_type<VoidPointer>::type set_auto_member_hook_t;
|
||||
typedef typename set_member_hook_type<VoidPointer>::type set_member_hook_t;
|
||||
|
||||
typedef typename uset_auto_base_hook_type<VoidPointer>::type unordered_set_auto_base_hook_t;
|
||||
typedef typename uset_base_hook_type<VoidPointer>::type unordered_set_base_hook_t;
|
||||
typedef typename uset_auto_member_hook_type<VoidPointer>::type unordered_set_auto_member_hook_t;
|
||||
typedef typename uset_member_hook_type<VoidPointer>::type unordered_set_member_hook_t;
|
||||
typedef typename splay_set_auto_base_hook_type<VoidPointer>::type splay_set_auto_base_hook_t;
|
||||
typedef typename splay_set_base_hook_type<VoidPointer>::type splay_set_base_hook_t;
|
||||
typedef typename splay_set_auto_member_hook_type<VoidPointer>::type splay_set_auto_member_hook_t;
|
||||
typedef typename splay_set_member_hook_type<VoidPointer>::type splay_set_member_hook_t;
|
||||
|
||||
typedef typename list_auto_base_hook_type<VoidPointer>::type list_auto_base_hook_t;
|
||||
typedef typename list_base_hook_type<VoidPointer>::type list_base_hook_t;
|
||||
typedef typename list_auto_member_hook_type<VoidPointer>::type list_auto_member_hook_t;
|
||||
typedef typename list_member_hook_type<VoidPointer>::type list_member_hook_t;
|
||||
typedef typename uset_auto_base_hook_type<VoidPointer>::type unordered_set_auto_base_hook_t;
|
||||
typedef typename uset_base_hook_type<VoidPointer>::type unordered_set_base_hook_t;
|
||||
typedef typename uset_auto_member_hook_type<VoidPointer>::type unordered_set_auto_member_hook_t;
|
||||
typedef typename uset_member_hook_type<VoidPointer>::type unordered_set_member_hook_t;
|
||||
|
||||
typedef typename slist_auto_base_hook_type<VoidPointer>::type slist_auto_base_hook_t;
|
||||
typedef typename slist_base_hook_type<VoidPointer>::type slist_base_hook_t;
|
||||
typedef typename slist_auto_member_hook_type<VoidPointer>::type slist_auto_member_hook_t;
|
||||
typedef typename slist_member_hook_type<VoidPointer>::type slist_member_hook_t;
|
||||
typedef typename list_auto_base_hook_type<VoidPointer>::type list_auto_base_hook_t;
|
||||
typedef typename list_base_hook_type<VoidPointer>::type list_base_hook_t;
|
||||
typedef typename list_auto_member_hook_type<VoidPointer>::type list_auto_member_hook_t;
|
||||
typedef typename list_member_hook_type<VoidPointer>::type list_member_hook_t;
|
||||
|
||||
typedef typename slist_auto_base_hook_type<VoidPointer>::type slist_auto_base_hook_t;
|
||||
typedef typename slist_base_hook_type<VoidPointer>::type slist_base_hook_t;
|
||||
typedef typename slist_auto_member_hook_type<VoidPointer>::type slist_auto_member_hook_t;
|
||||
typedef typename slist_member_hook_type<VoidPointer>::type slist_member_hook_t;
|
||||
|
||||
//Set members
|
||||
set_member_hook_t set_node_;
|
||||
set_auto_member_hook_t set_auto_node_;
|
||||
|
||||
//SplaySet members
|
||||
splay_set_member_hook_t splay_set_node_;
|
||||
splay_set_auto_member_hook_t splay_set_auto_node_;
|
||||
|
||||
//Unordered set members
|
||||
unordered_set_member_hook_t unordered_set_node_;
|
||||
unordered_set_auto_member_hook_t unordered_set_auto_node_;
|
||||
@@ -163,6 +191,11 @@ struct testvalue
|
||||
this->set_node_ = src.set_node_;
|
||||
this->set_auto_node_ = src.set_auto_node_;
|
||||
|
||||
splay_set_base_hook_t::operator=(src);
|
||||
splay_set_auto_base_hook_t::operator=(src);
|
||||
this->splay_set_node_ = src.splay_set_node_;
|
||||
this->splay_set_auto_node_ = src.splay_set_auto_node_;
|
||||
|
||||
unordered_set_base_hook_t::operator=(src);
|
||||
unordered_set_auto_base_hook_t::operator=(src);
|
||||
this->unordered_set_node_ = src.unordered_set_node_;
|
||||
@@ -190,6 +223,12 @@ struct testvalue
|
||||
set_node_.swap_nodes(other.set_node_);
|
||||
set_auto_node_.swap_nodes(other.set_auto_node_);
|
||||
|
||||
//SplaySet
|
||||
splay_set_base_hook_t::swap_nodes(other);
|
||||
splay_set_auto_base_hook_t::swap_nodes(other);
|
||||
splay_set_node_.swap_nodes(other.splay_set_node_);
|
||||
splay_set_auto_node_.swap_nodes(other.splay_set_auto_node_);
|
||||
|
||||
//Unordered set
|
||||
unordered_set_base_hook_t::swap_nodes(other);
|
||||
unordered_set_auto_base_hook_t::swap_nodes(other);
|
||||
|
||||
@@ -0,0 +1,469 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Olaf Krzikalla 2004-2006.
|
||||
// (C) Copyright Ion Gaztanaga 2006-2007.
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/intrusive for documentation.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/intrusive/detail/config_begin.hpp>
|
||||
#include <boost/intrusive/splay_set.hpp>
|
||||
#include <boost/intrusive/detail/pointer_to_other.hpp>
|
||||
#include "itestvalue.hpp"
|
||||
#include "smart_ptr.hpp"
|
||||
#include "common_functors.hpp"
|
||||
#include <vector>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include "test_macros.hpp"
|
||||
#include "test_container.hpp"
|
||||
#include <set>
|
||||
|
||||
namespace boost { namespace intrusive { namespace test {
|
||||
|
||||
template<class T, class O1, class O2, class O3, class O4>
|
||||
struct has_const_overloads<boost::intrusive::splay_multiset<T, O1, O2, O3, O4> >
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
using namespace boost::intrusive;
|
||||
template<class ValueTraits>
|
||||
struct test_splay_multiset
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
static void test_all (std::vector<value_type>& values, bool splay);
|
||||
static void test_sort(std::vector<value_type>& values, bool splay);
|
||||
static void test_insert(std::vector<value_type>& values, bool splay);
|
||||
static void test_swap(std::vector<value_type>& values, bool splay);
|
||||
static void test_find(std::vector<value_type>& values, bool splay);
|
||||
static void test_splay_up(std::vector<value_type>& values);
|
||||
static void test_splay_down(std::vector<value_type>& values);
|
||||
static void test_impl(bool splay);
|
||||
static void test_clone(std::vector<value_type>& values, bool splay);
|
||||
static void test_container_from_end(std::vector<value_type>& values, bool splay);
|
||||
};
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_all
|
||||
(std::vector<typename ValueTraits::value_type>& values, bool splay)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_multiset_type;
|
||||
{
|
||||
splay_multiset_type testset(values.begin(), values.end());
|
||||
test::test_container(testset);
|
||||
testset.clear();
|
||||
testset.insert(values.begin(), values.end());
|
||||
test::test_common_unordered_and_associative_container(testset, values);
|
||||
testset.clear();
|
||||
testset.insert(values.begin(), values.end());
|
||||
test::test_associative_container(testset, values);
|
||||
testset.clear();
|
||||
testset.insert(values.begin(), values.end());
|
||||
test::test_non_unique_container(testset, values);
|
||||
}
|
||||
test_sort(values, splay);
|
||||
test_insert(values, splay);
|
||||
test_swap(values, splay);
|
||||
test_find(values, splay);
|
||||
test_splay_up(values);
|
||||
test_splay_down(values);
|
||||
test_impl(splay);
|
||||
test_clone(values, splay);
|
||||
test_container_from_end(values, splay);
|
||||
}
|
||||
|
||||
//test case due to an error in tree implementation:
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_impl(bool splay)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
std::vector<value_type> values (5);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
values[i].value_ = i;
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
|
||||
multiset_type testset;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
testset.insert (values[i]);
|
||||
|
||||
testset.erase (testset.iterator_to (values[0]));
|
||||
testset.erase (testset.iterator_to (values[1]));
|
||||
testset.insert (values[1]);
|
||||
|
||||
testset.erase (testset.iterator_to (values[2]));
|
||||
testset.erase (testset.iterator_to (values[3]));
|
||||
}
|
||||
|
||||
//test: constructor, iterator, clear, reverse_iterator, front, back, size:
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_sort
|
||||
(std::vector<typename ValueTraits::value_type>& values, bool splay)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
|
||||
multiset_type testset1 (values.begin(), values.end());
|
||||
{ int init_values [] = { 1, 2, 2, 3, 4, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset1.begin() ); }
|
||||
|
||||
testset1.clear();
|
||||
BOOST_TEST (testset1.empty());
|
||||
|
||||
typedef splay_multiset
|
||||
<value_type
|
||||
, compare<even_odd>
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type2;
|
||||
multiset_type2 testset2 (&values[0], &values[0] + 6);
|
||||
{ int init_values [] = { 5, 3, 1, 4, 2, 2 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset2.rbegin() ); }
|
||||
|
||||
BOOST_TEST (testset2.begin()->value_ == 2);
|
||||
BOOST_TEST (testset2.rbegin()->value_ == 5);
|
||||
}
|
||||
|
||||
//test: insert, const_iterator, const_reverse_iterator, erase, iterator_to:
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_insert
|
||||
(std::vector<typename ValueTraits::value_type>& values, bool splay)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
|
||||
multiset_type testset;
|
||||
testset.insert(&values[0] + 2, &values[0] + 5);
|
||||
{ int init_values [] = { 1, 4, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset.begin() ); }
|
||||
|
||||
typename multiset_type::iterator i = testset.begin();
|
||||
BOOST_TEST (i->value_ == 1);
|
||||
|
||||
i = testset.insert (i, values[0]);
|
||||
BOOST_TEST (&*i == &values[0]);
|
||||
|
||||
{ int init_values [] = { 5, 4, 3, 1 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset.rbegin() ); }
|
||||
|
||||
i = testset.iterator_to (values[2]);
|
||||
BOOST_TEST (&*i == &values[2]);
|
||||
|
||||
i = multiset_type::s_iterator_to (values[2]);
|
||||
BOOST_TEST (&*i == &values[2]);
|
||||
|
||||
testset.erase(i);
|
||||
|
||||
{ int init_values [] = { 1, 3, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset.begin() ); }
|
||||
}
|
||||
|
||||
//test: insert (seq-version), swap, erase (seq-version), size:
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_swap
|
||||
(std::vector<typename ValueTraits::value_type>& values, bool splay)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
multiset_type testset1 (&values[0], &values[0] + 2);
|
||||
multiset_type testset2;
|
||||
testset2.insert (&values[0] + 2, &values[0] + 6);
|
||||
|
||||
{ int init_values [] = { 1, 2, 4, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset2.begin() ); }
|
||||
{ int init_values [] = { 2, 3 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset1.begin() ); }
|
||||
|
||||
testset1.swap (testset2);
|
||||
|
||||
{ int init_values [] = { 1, 2, 4, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset1.begin() ); }
|
||||
{ int init_values [] = { 2, 3 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset2.begin() ); }
|
||||
|
||||
testset1.erase (testset1.iterator_to(values[5]), testset1.end());
|
||||
BOOST_TEST (testset1.size() == 1);
|
||||
BOOST_TEST (&*testset1.begin() == &values[3]);
|
||||
}
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_splay_up
|
||||
(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
typedef typename multiset_type::iterator iterator;
|
||||
typedef std::multiset<value_type> orig_multiset_t;
|
||||
std::size_t num_values;
|
||||
std::multiset<value_type> original_testset (values.begin(), values.end());
|
||||
num_values = original_testset.size();
|
||||
|
||||
for(std::size_t i = 0; i != num_values; ++i){
|
||||
multiset_type testset (values.begin(), values.end());
|
||||
{
|
||||
iterator it = testset.begin();
|
||||
for(std::size_t j = 0; j != i; ++j, ++it){}
|
||||
testset.splay_up(it);
|
||||
}
|
||||
BOOST_TEST (testset.size() == num_values);
|
||||
iterator it = testset.begin();
|
||||
for( typename orig_multiset_t::const_iterator origit = original_testset.begin()
|
||||
, origitend = original_testset.end()
|
||||
; origit != origitend
|
||||
; ++origit, ++it){
|
||||
BOOST_TEST(*origit == *it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_splay_down
|
||||
(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
typedef typename multiset_type::iterator iterator;
|
||||
typedef std::multiset<value_type> orig_multiset_t;
|
||||
std::size_t num_values;
|
||||
std::multiset<value_type> original_testset (values.begin(), values.end());
|
||||
num_values = original_testset.size();
|
||||
|
||||
for(std::size_t i = 0; i != num_values; ++i){
|
||||
multiset_type testset (values.begin(), values.end());
|
||||
{
|
||||
iterator it = testset.begin();
|
||||
for(std::size_t j = 0; j != i; ++j, ++it){}
|
||||
BOOST_TEST(*it == *testset.splay_down(*it));
|
||||
}
|
||||
BOOST_TEST (testset.size() == num_values);
|
||||
iterator it = testset.begin();
|
||||
for( typename orig_multiset_t::const_iterator origit = original_testset.begin()
|
||||
, origitend = original_testset.end()
|
||||
; origit != origitend
|
||||
; ++origit, ++it){
|
||||
BOOST_TEST(*origit == *it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//test: find, equal_range (lower_bound, upper_bound):
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_find
|
||||
(std::vector<typename ValueTraits::value_type>& values, bool splay)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
multiset_type testset (values.begin(), values.end());
|
||||
typedef typename multiset_type::iterator iterator;
|
||||
|
||||
value_type cmp_val;
|
||||
cmp_val.value_ = 2;
|
||||
iterator i = testset.find (cmp_val);
|
||||
BOOST_TEST (i->value_ == 2);
|
||||
BOOST_TEST ((++i)->value_ == 2);
|
||||
std::pair<iterator,iterator> range = testset.equal_range (cmp_val);
|
||||
|
||||
BOOST_TEST (range.first->value_ == 2);
|
||||
BOOST_TEST (range.second->value_ == 3);
|
||||
BOOST_TEST (std::distance (range.first, range.second) == 2);
|
||||
|
||||
cmp_val.value_ = 7;
|
||||
BOOST_TEST (testset.find (cmp_val) == testset.end());
|
||||
}
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_clone
|
||||
(std::vector<typename ValueTraits::value_type>& values, bool splay)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
multiset_type testmultiset1 (&values[0], &values[0] + values.size());
|
||||
multiset_type testmultiset2;
|
||||
|
||||
testmultiset2.clone_from(testmultiset1, test::new_cloner<value_type>(), test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testmultiset2 == testmultiset1);
|
||||
testmultiset2.clear_and_dispose(test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testmultiset2.empty());
|
||||
}
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_multiset<ValueTraits>::test_container_from_end
|
||||
(std::vector<typename ValueTraits::value_type>& values, bool splay)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_multiset
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> multiset_type;
|
||||
|
||||
multiset_type testmultiset (&values[0], &values[0] + values.size());
|
||||
BOOST_TEST (testmultiset == multiset_type::container_from_end_iterator(testmultiset.end()));
|
||||
BOOST_TEST (testmultiset == multiset_type::container_from_end_iterator(testmultiset.cend()));
|
||||
}
|
||||
|
||||
template<class VoidPointer, bool constant_time_size>
|
||||
class test_main_template
|
||||
{
|
||||
public:
|
||||
int operator()()
|
||||
{
|
||||
for(int n = 0; n < 2; ++n){
|
||||
typedef testvalue<VoidPointer, constant_time_size> value_type;
|
||||
static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
|
||||
std::vector<testvalue<VoidPointer, constant_time_size> > data (6);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
data[i].value_ = random_init[i];
|
||||
|
||||
test_splay_multiset < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename value_type::splay_set_base_hook_t
|
||||
>::type
|
||||
>::test_all(data, 0 != (n%2));
|
||||
test_splay_multiset < typename detail::get_member_value_traits
|
||||
< value_type
|
||||
, member_hook< value_type
|
||||
, typename value_type::splay_set_member_hook_t
|
||||
, &value_type::splay_set_node_
|
||||
>
|
||||
>::type
|
||||
>::test_all(data, 0 != (n%2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template<class VoidPointer>
|
||||
class test_main_template<VoidPointer, false>
|
||||
{
|
||||
public:
|
||||
int operator()()
|
||||
{
|
||||
for(int n = 0; n < 2; ++n){
|
||||
typedef testvalue<VoidPointer, false> value_type;
|
||||
static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
|
||||
std::vector<testvalue<VoidPointer, false> > data (6);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
data[i].value_ = random_init[i];
|
||||
|
||||
test_splay_multiset < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename value_type::splay_set_base_hook_t
|
||||
>::type
|
||||
>::test_all(data, 0 != (n%2));
|
||||
|
||||
test_splay_multiset < typename detail::get_member_value_traits
|
||||
< value_type
|
||||
, member_hook< value_type
|
||||
, typename value_type::splay_set_member_hook_t
|
||||
, &value_type::splay_set_node_
|
||||
>
|
||||
>::type
|
||||
>::test_all(data, 0 != (n%2));
|
||||
|
||||
test_splay_multiset < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename value_type::splay_set_auto_base_hook_t
|
||||
>::type
|
||||
>::test_all(data, 0 != (n%2));
|
||||
|
||||
test_splay_multiset < typename detail::get_member_value_traits
|
||||
< value_type
|
||||
, member_hook< value_type
|
||||
, typename value_type::splay_set_auto_member_hook_t
|
||||
, &value_type::splay_set_auto_node_
|
||||
>
|
||||
>::type
|
||||
>::test_all(data, 0 != (n%2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
//Explicit instantiations of non-counted classes
|
||||
//template class multiset
|
||||
// <set_base_raw, std::less<set_base_raw::value_type>, false>;
|
||||
//template class multiset
|
||||
// <set_member_raw, std::less<set_member_raw::value_type>, false>;
|
||||
//template class multiset
|
||||
// <set_auto_base_raw, std::less<set_auto_base_raw::value_type>, false>;
|
||||
//template class multiset
|
||||
// <set_auto_member_raw, std::less<set_auto_member_raw::value_type>, false>;
|
||||
//template class multiset
|
||||
// <set_base_smart, std::less<set_base_smart::value_type>, false>;
|
||||
//template class multiset
|
||||
// <set_member_smart, std::less<set_member_smart::value_type>, false>;
|
||||
//template class multiset
|
||||
// <set_auto_base_smart, std::less<set_auto_base_smart::value_type>, false>;
|
||||
//template class multiset
|
||||
// <set_auto_member_smart, std::less<set_auto_member_smart::value_type>, false>;
|
||||
|
||||
//Explicit instantiation of counted classes
|
||||
//template class multiset
|
||||
// <set_base_raw_t, std::less<set_base_raw_t::value_type>, true>;
|
||||
//template class multiset
|
||||
// <set_member_raw_t, std::less<set_member_raw_t::value_type>, true>;
|
||||
//template class multiset
|
||||
// <set_base_smart_t, std::less<set_base_smart_t::value_type>, true>;
|
||||
//template class multiset
|
||||
// <set_member_smart_t, std::less<set_member_smart_t::value_type>, true>;
|
||||
|
||||
int main( int, char* [] )
|
||||
{
|
||||
test_main_template<void*, false>()();
|
||||
test_main_template<smart_ptr<void>, false>()();
|
||||
test_main_template<void*, true>()();
|
||||
test_main_template<smart_ptr<void>, true>()();
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2007.
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/intrusive for documentation.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#include <boost/intrusive/detail/config_begin.hpp>
|
||||
#include <boost/intrusive/splay_set.hpp>
|
||||
#include <boost/intrusive/detail/pointer_to_other.hpp>
|
||||
#include "itestvalue.hpp"
|
||||
#include "smart_ptr.hpp"
|
||||
#include "common_functors.hpp"
|
||||
#include <vector>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include "test_macros.hpp"
|
||||
#include "test_container.hpp"
|
||||
#include <set>
|
||||
|
||||
namespace boost { namespace intrusive { namespace test {
|
||||
|
||||
template<class T, class O1, class O2, class O3, class O4>
|
||||
struct has_const_overloads<boost::intrusive::splay_set<T, O1, O2, O3, O4> >
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
using namespace boost::intrusive;
|
||||
|
||||
template<class ValueTraits>
|
||||
struct test_splay_set
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
static void test_all(std::vector<value_type>& values);
|
||||
static void test_sort(std::vector<value_type>& values);
|
||||
static void test_insert(std::vector<value_type>& values);
|
||||
static void test_swap(std::vector<value_type>& values);
|
||||
static void test_find(std::vector<value_type>& values);
|
||||
static void test_splay_up(std::vector<value_type>& values);
|
||||
static void test_splay_down(std::vector<value_type>& values);
|
||||
static void test_impl();
|
||||
static void test_clone(std::vector<value_type>& values);
|
||||
static void test_container_from_end(std::vector<value_type>& values);
|
||||
};
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>::test_all(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_set_type;
|
||||
{
|
||||
splay_set_type testset(values.begin(), values.end());
|
||||
test::test_container(testset);
|
||||
testset.clear();
|
||||
testset.insert(values.begin(), values.end());
|
||||
test::test_common_unordered_and_associative_container(testset, values);
|
||||
testset.clear();
|
||||
testset.insert(values.begin(), values.end());
|
||||
test::test_associative_container(testset, values);
|
||||
testset.clear();
|
||||
testset.insert(values.begin(), values.end());
|
||||
test::test_unique_container(testset, values);
|
||||
}
|
||||
|
||||
test_sort(values);
|
||||
test_insert(values);
|
||||
test_swap(values);
|
||||
test_find(values);
|
||||
test_splay_up(values);
|
||||
test_splay_down(values);
|
||||
test_impl();
|
||||
test_clone(values);
|
||||
test_container_from_end(values);
|
||||
}
|
||||
|
||||
//test case due to an error in tree implementation:
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>::test_impl()
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
std::vector<value_type> values (5);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
values[i].value_ = i;
|
||||
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_set_type;
|
||||
splay_set_type testset;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
testset.insert (values[i]);
|
||||
|
||||
testset.erase (testset.iterator_to (values[0]));
|
||||
testset.erase (testset.iterator_to (values[1]));
|
||||
testset.insert (values[1]);
|
||||
|
||||
testset.erase (testset.iterator_to (values[2]));
|
||||
testset.erase (testset.iterator_to (values[3]));
|
||||
}
|
||||
|
||||
//test: constructor, iterator, clear, reverse_iterator, front, back, size:
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>::test_sort(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_set_type;
|
||||
splay_set_type testset1 (values.begin(), values.end());
|
||||
{ int init_values [] = { 1, 2, 3, 4, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset1.begin() ); }
|
||||
|
||||
testset1.clear();
|
||||
BOOST_TEST (testset1.empty());
|
||||
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, compare<even_odd>
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> set_type2;
|
||||
set_type2 testset2 (&values[0], &values[0] + 6);
|
||||
{ int init_values [] = { 5, 3, 1, 4, 2 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset2.rbegin() ); }
|
||||
BOOST_TEST (testset2.begin()->value_ == 2);
|
||||
BOOST_TEST (testset2.rbegin()->value_ == 5);
|
||||
}
|
||||
|
||||
//test: insert, const_iterator, const_reverse_iterator, erase, s_iterator_to:
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>::test_insert(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_set_type;
|
||||
splay_set_type testset;
|
||||
testset.insert(&values[0] + 2, &values[0] + 5);
|
||||
|
||||
const splay_set_type& const_testset = testset;
|
||||
{ int init_values [] = { 1, 4, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, const_testset.begin() ); }
|
||||
|
||||
typename splay_set_type::iterator i = testset.begin();
|
||||
BOOST_TEST (i->value_ == 1);
|
||||
|
||||
i = testset.insert (i, values[0]);
|
||||
BOOST_TEST (&*i == &values[0]);
|
||||
|
||||
{ int init_values [] = { 5, 4, 3, 1 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset.rbegin() ); }
|
||||
|
||||
i = testset.iterator_to (values[2]);
|
||||
BOOST_TEST (&*i == &values[2]);
|
||||
|
||||
i = splay_set_type::s_iterator_to(values[2]);
|
||||
BOOST_TEST (&*i == &values[2]);
|
||||
|
||||
testset.erase (i);
|
||||
{ int init_values [] = { 1, 3, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset.begin() ); }
|
||||
}
|
||||
|
||||
//test: insert (seq-version), swap, erase (seq-version), size:
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>::test_swap(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_set_type;
|
||||
splay_set_type testset1 (&values[0], &values[0] + 2);
|
||||
splay_set_type testset2;
|
||||
testset2.insert (&values[0] + 2, &values[0] + 6);
|
||||
testset1.swap (testset2);
|
||||
|
||||
{ int init_values [] = { 1, 2, 4, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset1.begin() ); }
|
||||
|
||||
{ int init_values [] = { 2, 3 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset2.begin() ); }
|
||||
|
||||
testset1.erase (testset1.iterator_to(values[5]), testset1.end());
|
||||
BOOST_TEST (testset1.size() == 1);
|
||||
// BOOST_TEST (&testset1.front() == &values[3]);
|
||||
BOOST_TEST (&*testset1.begin() == &values[3]);
|
||||
}
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>::test_splay_up
|
||||
(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> set_type;
|
||||
typedef typename set_type::iterator iterator;
|
||||
typedef std::set<value_type> orig_set_t;
|
||||
std::size_t num_values;
|
||||
std::set<value_type> original_testset (values.begin(), values.end());
|
||||
num_values = original_testset.size();
|
||||
|
||||
for(std::size_t i = 0; i != num_values; ++i){
|
||||
set_type testset (values.begin(), values.end());
|
||||
{
|
||||
iterator it = testset.begin();
|
||||
for(std::size_t j = 0; j != i; ++j, ++it){}
|
||||
testset.splay_up(it);
|
||||
}
|
||||
BOOST_TEST (testset.size() == num_values);
|
||||
iterator it = testset.begin();
|
||||
for( typename orig_set_t::const_iterator origit = original_testset.begin()
|
||||
, origitend = original_testset.end()
|
||||
; origit != origitend
|
||||
; ++origit, ++it){
|
||||
BOOST_TEST(*origit == *it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>::test_splay_down
|
||||
(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, size_type<std::size_t>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> set_type;
|
||||
typedef typename set_type::iterator iterator;
|
||||
typedef std::set<value_type> orig_set_t;
|
||||
std::size_t num_values;
|
||||
std::set<value_type> original_testset (values.begin(), values.end());
|
||||
num_values = original_testset.size();
|
||||
|
||||
for(std::size_t i = 0; i != num_values; ++i){
|
||||
set_type testset (values.begin(), values.end());
|
||||
BOOST_TEST(testset.size() == num_values);
|
||||
{
|
||||
iterator it = testset.begin();
|
||||
for(std::size_t j = 0; j != i; ++j, ++it){}
|
||||
BOOST_TEST(*it == *testset.splay_down(*it));
|
||||
}
|
||||
BOOST_TEST (testset.size() == num_values);
|
||||
iterator it = testset.begin();
|
||||
for( typename orig_set_t::const_iterator origit = original_testset.begin()
|
||||
, origitend = original_testset.end()
|
||||
; origit != origitend
|
||||
; ++origit, ++it){
|
||||
BOOST_TEST(*origit == *it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//test: find, equal_range (lower_bound, upper_bound):
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>::test_find(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_set_type;
|
||||
splay_set_type testset (values.begin(), values.end());
|
||||
typedef typename splay_set_type::iterator iterator;
|
||||
|
||||
value_type cmp_val;
|
||||
cmp_val.value_ = 2;
|
||||
iterator i = testset.find (cmp_val);
|
||||
BOOST_TEST (i->value_ == 2);
|
||||
BOOST_TEST ((++i)->value_ != 2);
|
||||
std::pair<iterator,iterator> range = testset.equal_range (cmp_val);
|
||||
|
||||
BOOST_TEST (range.first->value_ == 2);
|
||||
BOOST_TEST (range.second->value_ == 3);
|
||||
BOOST_TEST (std::distance (range.first, range.second) == 1);
|
||||
|
||||
cmp_val.value_ = 7;
|
||||
BOOST_TEST (testset.find (cmp_val) == testset.end());
|
||||
}
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>
|
||||
::test_clone(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_set_type;
|
||||
|
||||
splay_set_type testset1 (&values[0], &values[0] + values.size());
|
||||
splay_set_type testset2;
|
||||
|
||||
testset2.clone_from(testset1, test::new_cloner<value_type>(), test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testset2 == testset1);
|
||||
testset2.clear_and_dispose(test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testset2.empty());
|
||||
}
|
||||
|
||||
template<class ValueTraits>
|
||||
void test_splay_set<ValueTraits>
|
||||
::test_container_from_end(std::vector<typename ValueTraits::value_type>& values)
|
||||
{
|
||||
typedef typename ValueTraits::value_type value_type;
|
||||
typedef splay_set
|
||||
< value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<value_type::constant_time_size>
|
||||
> splay_set_type;
|
||||
splay_set_type testset (&values[0], &values[0] + values.size());
|
||||
BOOST_TEST (testset == splay_set_type::container_from_end_iterator(testset.end()));
|
||||
BOOST_TEST (testset == splay_set_type::container_from_end_iterator(testset.cend()));
|
||||
}
|
||||
|
||||
template<class VoidPointer, bool constant_time_size>
|
||||
class test_main_template
|
||||
{
|
||||
public:
|
||||
int operator()()
|
||||
{
|
||||
typedef testvalue<VoidPointer, constant_time_size> value_type;
|
||||
static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
|
||||
std::vector<testvalue<VoidPointer, constant_time_size> > data (6);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
data[i].value_ = random_init[i];
|
||||
|
||||
test_splay_set < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename value_type::splay_set_base_hook_t
|
||||
>::type
|
||||
>::test_all(data);
|
||||
test_splay_set < typename detail::get_member_value_traits
|
||||
< value_type
|
||||
, member_hook< value_type
|
||||
, typename value_type::splay_set_member_hook_t
|
||||
, &value_type::splay_set_node_
|
||||
>
|
||||
>::type
|
||||
>::test_all(data);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template<class VoidPointer>
|
||||
class test_main_template<VoidPointer, false>
|
||||
{
|
||||
public:
|
||||
int operator()()
|
||||
{
|
||||
typedef testvalue<VoidPointer, false> value_type;
|
||||
static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
|
||||
std::vector<testvalue<VoidPointer, false> > data (6);
|
||||
for (int i = 0; i < 6; ++i)
|
||||
data[i].value_ = random_init[i];
|
||||
|
||||
test_splay_set < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename value_type::splay_set_base_hook_t
|
||||
>::type
|
||||
>::test_all(data);
|
||||
|
||||
test_splay_set < typename detail::get_member_value_traits
|
||||
< value_type
|
||||
, member_hook< value_type
|
||||
, typename value_type::splay_set_member_hook_t
|
||||
, &value_type::splay_set_node_
|
||||
>
|
||||
>::type
|
||||
>::test_all(data);
|
||||
|
||||
test_splay_set < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename value_type::splay_set_auto_base_hook_t
|
||||
>::type
|
||||
>::test_all(data);
|
||||
|
||||
test_splay_set < typename detail::get_member_value_traits
|
||||
< value_type
|
||||
, member_hook< value_type
|
||||
, typename value_type::splay_set_auto_member_hook_t
|
||||
, &value_type::splay_set_auto_node_
|
||||
>
|
||||
>::type
|
||||
>::test_all(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
int main( int, char* [] )
|
||||
{
|
||||
test_main_template<void*, false>()();
|
||||
test_main_template<smart_ptr<void>, false>()();
|
||||
test_main_template<void*, true>()();
|
||||
test_main_template<smart_ptr<void>, true>()();
|
||||
return boost::report_errors();
|
||||
}
|
||||
#include <boost/intrusive/detail/config_end.hpp>
|
||||
+35
-2
@@ -14,11 +14,18 @@
|
||||
#define BOOST_INTRUSIVE_TEST_CONTAINER_HPP
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/intrusive/detail/mpl.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace intrusive {
|
||||
namespace test {
|
||||
|
||||
template<class T>
|
||||
struct has_const_overloads
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
void test_container( Container & c )
|
||||
{
|
||||
@@ -151,7 +158,7 @@ void test_common_unordered_and_associative_container(Container & c, Data & d)
|
||||
}
|
||||
|
||||
template< class Container, class Data >
|
||||
void test_associative_container_invariants(Container & c, Data & d)
|
||||
void test_associative_container_invariants(Container & c, Data & d, boost::intrusive::detail::true_type)
|
||||
{
|
||||
typedef typename Container::const_iterator const_iterator;
|
||||
for( typename Data::const_iterator di = d.begin(), de = d.end();
|
||||
@@ -177,6 +184,19 @@ void test_associative_container_invariants(Container & c, Data & d)
|
||||
}
|
||||
}
|
||||
|
||||
template< class Container, class Data >
|
||||
void test_associative_container_invariants(Container & c, Data & d, boost::intrusive::detail::false_type)
|
||||
{}
|
||||
|
||||
template< class Container, class Data >
|
||||
void test_associative_container_invariants(Container & c, Data & d)
|
||||
{
|
||||
using namespace boost::intrusive;
|
||||
typedef typename detail::remove_const<Container>::type Type;
|
||||
typedef detail::bool_<has_const_overloads<Type>::value> enabler;
|
||||
test_associative_container_invariants(c, d, enabler());
|
||||
}
|
||||
|
||||
template< class Container, class Data >
|
||||
void test_associative_container(Container & c, Data & d)
|
||||
{
|
||||
@@ -194,7 +214,7 @@ void test_associative_container(Container & c, Data & d)
|
||||
}
|
||||
|
||||
template< class Container, class Data >
|
||||
void test_unordered_associative_container_invariants(Container & c, Data & d)
|
||||
void test_unordered_associative_container_invariants(Container & c, Data & d, boost::intrusive::detail::true_type)
|
||||
{
|
||||
typedef typename Container::size_type size_type;
|
||||
typedef typename Container::const_iterator const_iterator;
|
||||
@@ -224,6 +244,19 @@ void test_unordered_associative_container_invariants(Container & c, Data & d)
|
||||
BOOST_TEST( total_objects == c.size() );
|
||||
}
|
||||
|
||||
template< class Container, class Data >
|
||||
void test_unordered_associative_container_invariants(Container & c, Data & d, boost::intrusive::detail::false_type)
|
||||
{}
|
||||
|
||||
template< class Container, class Data >
|
||||
void test_unordered_associative_container_invariants(Container & c, Data & d)
|
||||
{
|
||||
using namespace boost::intrusive;
|
||||
typedef typename detail::remove_const<Container>::type Type;
|
||||
typedef detail::bool_<has_const_overloads<Type>::value> enabler;
|
||||
test_unordered_associative_container_invariants(c, d, enabler());
|
||||
}
|
||||
|
||||
template< class Container, class Data >
|
||||
void test_unordered_associative_container(Container & c, Data & d)
|
||||
{
|
||||
|
||||
@@ -317,7 +317,7 @@ void test_unordered_multiset<ValueTraits>
|
||||
src(testset1.begin(), testset1.end());
|
||||
std::multiset<typename ValueTraits::value_type>
|
||||
dst(testset2.begin(), testset2.end());
|
||||
BOOST_TEST (src == dst);
|
||||
BOOST_TEST (src.size() == dst.size() && std::equal(src.begin(), src.end(), dst.begin()));
|
||||
testset2.clear_and_dispose(test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testset2.empty());
|
||||
}
|
||||
@@ -334,7 +334,7 @@ void test_unordered_multiset<ValueTraits>
|
||||
src(testset1.begin(), testset1.end());
|
||||
std::multiset<typename ValueTraits::value_type>
|
||||
dst(testset2.begin(), testset2.end());
|
||||
BOOST_TEST (src == dst);
|
||||
BOOST_TEST (src.size() == dst.size() && std::equal(src.begin(), src.end(), dst.begin()));
|
||||
testset2.clear_and_dispose(test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testset2.empty());
|
||||
}
|
||||
@@ -351,7 +351,7 @@ void test_unordered_multiset<ValueTraits>
|
||||
src(testset1.begin(), testset1.end());
|
||||
std::multiset<typename ValueTraits::value_type>
|
||||
dst(testset2.begin(), testset2.end());
|
||||
BOOST_TEST (src == dst);
|
||||
BOOST_TEST (src.size() == dst.size() && std::equal(src.begin(), src.end(), dst.begin()));
|
||||
testset2.clear_and_dispose(test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testset2.empty());
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ void test_unordered_set<ValueTraits>
|
||||
src(testset1.begin(), testset1.end());
|
||||
std::set<typename ValueTraits::value_type>
|
||||
dst(testset2.begin(), testset2.end());
|
||||
BOOST_TEST (src == dst );
|
||||
BOOST_TEST (src.size() == dst.size() && std::equal(src.begin(), src.end(), dst.begin()));
|
||||
testset2.clear_and_dispose(test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testset2.empty());
|
||||
}
|
||||
@@ -308,7 +308,7 @@ void test_unordered_set<ValueTraits>
|
||||
src(testset1.begin(), testset1.end());
|
||||
std::set<typename ValueTraits::value_type>
|
||||
dst(testset2.begin(), testset2.end());
|
||||
BOOST_TEST (src == dst );
|
||||
BOOST_TEST (src.size() == dst.size() && std::equal(src.begin(), src.end(), dst.begin()));
|
||||
testset2.clear_and_dispose(test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testset2.empty());
|
||||
}
|
||||
@@ -325,7 +325,7 @@ void test_unordered_set<ValueTraits>
|
||||
src(testset1.begin(), testset1.end());
|
||||
std::set<typename ValueTraits::value_type>
|
||||
dst(testset2.begin(), testset2.end());
|
||||
BOOST_TEST (src == dst );
|
||||
BOOST_TEST (src.size() == dst.size() && std::equal(src.begin(), src.end(), dst.begin()));
|
||||
testset2.clear_and_dispose(test::delete_disposer<value_type>());
|
||||
BOOST_TEST (testset2.empty());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user