multi_index/test/test_rearrange.cpp
Joaquín M López Muñoz 47b172ab68 Boost 1.35 version of Boost.MultiIndex
allocator_utilities.hpp: added partial_std_allocator_wrapper::value_type
composite_key.hpp: used hash_fwd.hpp
auto_space.hpp: added support for non-standard allocators
bidir_node_iterator.hpp: moved friend-injected operators out of class
copy_map.hpp: added support for non-standard allocators
hash_index_args.hpp: removed deprecated use of <boost/functional/hash/hash.hpp>
hash_index_iterator.hpp: moved friend-injected operators our of class
hash_index_node.hpp: added support for non-standard allocators
header_holder.hpp:added support for non-standard allocators
index_base.hpp: added support for non-standard allocators, added modify_rollback, added small improvement to modify
index_loader.hpp: added support for non-standard allocators
index_matcher.hpp: added support for non-standard allocators
index_node_base.hpp: added support for non-standard allocators
iter_adaptor.hpp: added some out-of-class operators to alleviate a MSVC++ 6.0 problem
modify_key_adaptor.hpp: renamed some vars to accomudate broader usage scope
node_type.hpp: added support for non-standard allocators
ord_index_node.hpp: added support for non-standard allocators
ord_index_ops.hpp: implemented a more efficient equal_range
rnd_index_loader.hpp: added support for non-standard allocators
rnd_index_node.hpp: added support for non-standard allocators
rnd_index_ops.hpp: added support for non-standard allocators
rnd_index_ptr_array.hpp: added support for non-standard allocators
rnd_node_iterator.hpp: moved friend-injected operators out of class
seq_index_node.hpp: added support for non-standard allocators
seq_index_ops.hpp: added support for non-standard allocators
uintptr_type.hpp: added support for __int64
unbounded.hpp: fixed ODR problem
value_compare.hpp: fixed a small unefficiency
global_fun: initial commit
hashed_index.hpp: added support for non-standard allocators, added c[r]{begin|end}, [local_]iterator_to, rollback modify
identity_fwd.hpp: fixed wrong include guard name
key_extractors.hpp: added global_fun
mem_fun.hpp: removed superfluous =0's
ordered_index.hpp: added support for non-standard allocators, added c[r]{begin|end}, iterator_to, rollback modify, improved equal_range and range, added conformance to DR 233
random_access_index.hpp: added support for non-standard allocators, added c[r]{begin|end}, iterator_to, rollback modify, added conformance to 23.1.1/9
sequenced_index.hpp: added support for non-standard allocators, added c[r]{begin|end}, iterator_to, rollback modify, added conformance to 23.1.1/9, improved resize
multi_index_container.hpp: added support for non-standard allocators, improved ctor_args_list, rollback modify
acknowledgements.html: added entry for Boost 1.35
examples.html: renamed example 2, added B.IP example/composite_keys.cpp
future_work.html: removed entry on bimap
hash_indices.html: added c[r]{begin|end}, [local_]iterator_to, rollback modify
reference/index.html: added global_fun
reference/key_extraction.html: added global_fun, added technical correction
multi_index_container.html: added support for non-standard allocators
ord_indices.html: added c[r]{begin|end}, iterator_to, rollback modify
rnd_indices.html: added c[r]{begin|end}, iterator_to, rollback modify
seq_indices.html: added c[r]{begin|end}, iterator_to, rollback modify
release_notes.html: added entry for Boost 1.35
tests.html: added new serialization test file
basics.html: added rollback modify
creation.html: added support for non-standard allocators
tutorial/indices.html: added iterator_to
tutorial/key_extraction.html: added global_fun
composite_keys.cpp: fixed technicality
fun_key.cpp: was memfun_key.cpp, added global_fun
ip_allocator.cpp: initial commit
example/Jamfile.v2: renamed memfun_key, added ip_allocator
test_perf.cpp: fixed technicality
employee.hpp: used a non-standard allocator
test/Jamfile.v2: added new test file
non_std_allocator.hpp: initial commit
pair_of_ints.hpp: added decrement facilities
test_capacity.cpp: added extra check on resize
test_copy_assignment.cpp: added test for 23.1.1/9
test_iterators.cpp: added tests for c[r]{begin|end} and [local_]iterator_to, fixed technicality
test_key_extractors.cpp: added tests for global_fun
test_modifiers.cpp: added tests dor DR 233, fixed technicality
test_range.cpp: added extra checks to secure range refactoring
test_rearrange.cpp: fixed technicality
test_serialization.cpp: added new test file
test_serialization1.cpp: corrected include, used a non-standard allocator
test_serialization2.cpp: corrected include, used a non-standard allocator, split some stuff ro test_serialization3.cpp
test_serialization3.cpp: initial commit
test_serialization3.hpp: initial commit
test_serialization_template.hpp: removed some reliance on ADL
test_update.cpp: addes tests for rollback modify, fixed technicality

[SVN r39922]
2007-10-11 10:57:30 +00:00

140 lines
3.4 KiB
C++

/* Boost.MultiIndex test for rearrange operations.
*
* Copyright 2003-2007 Joaquín M López Muñoz.
* 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/multi_index for library home page.
*/
#include "test_rearrange.hpp"
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <algorithm>
#include <iterator>
#include "pre_multi_index.hpp"
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/next_prior.hpp>
#include <boost/ref.hpp>
#include <boost/test/test_tools.hpp>
#include <vector>
using namespace boost::multi_index;
#undef _
#define _ ,
#undef CHECK_EQUAL
#define CHECK_EQUAL(p,check_range) \
{\
int v[]=check_range;\
std::size_t size_v=sizeof(v)/sizeof(int);\
BOOST_CHECK(std::size_t(std::distance((p).begin(),(p).end()))==size_v);\
BOOST_CHECK(std::equal((p).begin(),(p).end(),&v[0]));\
}
#undef CHECK_VOID_RANGE
#define CHECK_VOID_RANGE(p) BOOST_CHECK((p).first==(p).second)
#if BOOST_WORKAROUND(__MWERKS__,<=0x3003)
/* The "ISO C++ Template Parser" option makes CW8.3 incorrectly fail at
* expressions of the form sizeof(x) where x is an array local to a
* template function.
*/
#pragma parse_func_templ off
#endif
template<typename Sequence>
static void local_test_rearrange(BOOST_EXPLICIT_TEMPLATE_TYPE(Sequence))
{
typedef typename Sequence::iterator iterator;
typedef typename Sequence::value_type value_type;
Sequence sc;
sc.push_back(0);
sc.push_back(1);
sc.push_back(2);
sc.push_back(3);
sc.push_back(4);
sc.push_back(5);
iterator it;
it=sc.begin();
std::advance(it,3);
sc.relocate(sc.begin(),it);
CHECK_EQUAL(sc,{3 _ 0 _ 1 _ 2 _ 4 _ 5});
BOOST_CHECK(it==sc.begin());
sc.relocate(it,it);
CHECK_EQUAL(sc,{3 _ 0 _ 1 _ 2 _ 4 _ 5});
std::advance(it,3);
sc.relocate(sc.end(),it,sc.end());
CHECK_EQUAL(sc,{3 _ 0 _ 1 _ 2 _ 4 _ 5});
sc.relocate(sc.begin(),it,it);
CHECK_EQUAL(sc,{3 _ 0 _ 1 _ 2 _ 4 _ 5});
iterator it2;
it2=sc.begin();
++it2;
sc.relocate(it2,it,sc.end());
CHECK_EQUAL(sc,{3 _ 2 _ 4 _ 5 _ 0 _ 1});
BOOST_CHECK(std::distance(it,it2)==3);
sc.relocate(boost::prior(sc.end()),it,it2);
CHECK_EQUAL(sc,{3 _ 0 _ 2 _ 4 _ 5 _ 1});
std::vector<boost::reference_wrapper<const value_type> > v;
for(iterator it3=sc.begin();it3!=sc.end();++it3){
v.push_back(boost::cref(*it3));
}
sc.rearrange(v.begin());
BOOST_CHECK(std::equal(sc.begin(),sc.end(),v.begin()));
std::reverse(v.begin(),v.end());
sc.rearrange(v.begin());
BOOST_CHECK(std::equal(sc.begin(),sc.end(),v.begin()));
std::sort(v.begin(),v.end());
sc.rearrange(v.begin());
BOOST_CHECK(std::equal(sc.begin(),sc.end(),v.begin()));
std::reverse(v.begin(),v.begin()+v.size()/2);
sc.rearrange(v.begin());
BOOST_CHECK(std::equal(sc.begin(),sc.end(),v.begin()));
}
#if BOOST_WORKAROUND(__MWERKS__,<=0x3003)
#pragma parse_func_templ reset
#endif
void test_rearrange()
{
typedef multi_index_container<
int,
indexed_by<sequenced<> >
> int_list;
/* MSVC++ 6.0 chokes on local_test_rearrange without this
* explicit instantiation
*/
int_list il;
local_test_rearrange<int_list>();
typedef multi_index_container<
int,
indexed_by<random_access<> >
> int_vector;
int_vector iv;
local_test_rearrange<int_vector>();
}