multi_index/test/test_copy_assignment.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

162 lines
4.3 KiB
C++

/* Boost.MultiIndex test for copying and assignment.
*
* 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_copy_assignment.hpp"
#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <algorithm>
#include <list>
#include <numeric>
#include <vector>
#include "pre_multi_index.hpp"
#include "employee.hpp"
#include <boost/test/test_tools.hpp>
using namespace boost::multi_index;
#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 test_assign(BOOST_EXPLICIT_TEMPLATE_TYPE(Sequence))
{
Sequence s;
int a[]={0,1,2,3,4,5};
std::size_t sa=sizeof(a)/sizeof(a[0]);
s.assign(&a[0],&a[sa]);
BOOST_CHECK(s.size()==sa&&std::equal(s.begin(),s.end(),&a[0]));
s.assign(&a[0],&a[sa]);
BOOST_CHECK(s.size()==sa&&std::equal(s.begin(),s.end(),&a[0]));
s.assign((std::size_t)18,37);
BOOST_CHECK(s.size()==18&&std::accumulate(s.begin(),s.end(),0)==666);
s.assign((std::size_t)12,167);
BOOST_CHECK(s.size()==12&&std::accumulate(s.begin(),s.end(),0)==2004);
}
#if BOOST_WORKAROUND(__MWERKS__,<=0x3003)
#pragma parse_func_templ reset
#endif
template<typename Sequence>
static void test_integral_assign(BOOST_EXPLICIT_TEMPLATE_TYPE(Sequence))
{
/* Special cases described in 23.1.1/9: integral types must not
* be taken as iterators in assign(f,l) and insert(p,f,l).
*/
Sequence s;
s.assign(5,10);
BOOST_CHECK(s.size()==5&&std::accumulate(s.begin(),s.end(),0)==50);
s.assign(2u,5u);
BOOST_CHECK(s.size()==2&&std::accumulate(s.begin(),s.end(),0)==10);
s.clear();
s.insert(s.begin(),5,10);
BOOST_CHECK(s.size()==5&&std::accumulate(s.begin(),s.end(),0)==50);
s.insert(s.begin(),2u,5u);
BOOST_CHECK(s.size()==7&&std::accumulate(s.begin(),s.end(),0)==60);
}
void test_copy_assignment()
{
employee_set es;
employee_set es2(es);
employee_set::allocator_type al=es.get_allocator();
al=get<1>(es).get_allocator();
al=get<2>(es).get_allocator();
al=get<3>(es).get_allocator();
al=get<4>(es).get_allocator();
al=get<5>(es).get_allocator();
BOOST_CHECK(es2.empty());
es2.insert(employee(0,"Joe",31,1123));
es2.insert(employee(1,"Robert",27,5601));
es2.insert(employee(2,"John",40,7889));
es2.insert(employee(2,"Aristotle",2388,3357)); /* clash */
es2.insert(employee(3,"Albert",20,9012));
es2.insert(employee(4,"John",57,1002));
es2.insert(employee(0,"Andrew",60,2302)); /* clash */
employee_set es3(es2);
BOOST_CHECK(es2==es3);
BOOST_CHECK(get<2>(es2)==get<2>(es3));
BOOST_CHECK(get<3>(es2)==get<3>(es3));
BOOST_CHECK(get<5>(es2)==get<5>(es3));
employee_set es4;
employee_set_by_name& i1=get<name>(es4);
i1=get<1>(es2);
BOOST_CHECK(es4==es2);
employee_set es5;
employee_set_by_age& i2=get<age>(es5);
i2=get<2>(es2);
BOOST_CHECK(i2==get<2>(es2));
employee_set es6;
employee_set_as_inserted& i3=get<as_inserted>(es6);
i3=get<3>(es2);
BOOST_CHECK(i3==get<3>(es2));
employee_set es7;
employee_set_randomly& i5=get<randomly>(es7);
i5=get<5>(es2);
BOOST_CHECK(i5==get<5>(es2));
std::list<employee> l;
l.push_back(employee(3,"Anna",31,5388));
l.push_back(employee(1,"Rachel",27,9012));
l.push_back(employee(2,"Agatha",40,1520));
#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
employee_set es8;
es8.insert(l.begin(),l.end());
#else
employee_set es8(l.begin(),l.end());
#endif
l.sort();
BOOST_CHECK(es8.size()==l.size()&&
std::equal(es8.begin(),es8.end(),l.begin()));
/* MSVC++ 6.0 chokes on test_assign without this explicit instantiation */
multi_index_container<int,indexed_by<sequenced<> > > s1;
test_assign<multi_index_container<int,indexed_by<sequenced<> > > >();
test_integral_assign<
multi_index_container<int,indexed_by<sequenced<> > > >();
multi_index_container<int,indexed_by<random_access<> > > s2;
test_assign<multi_index_container<int,indexed_by<random_access<> > > >();
test_integral_assign<
multi_index_container<int,indexed_by<random_access<> > > >();
}