mirror of
https://github.com/boostorg/multi_index.git
synced 2026-01-19 04:22:11 +00:00
* removed simulated variadic function args * removed detail/allocator_traits.hpp in favor of Boost.Core functionality * removed usage of Boost.Move * avoided pessimizing-move warnings * removed usage of BOOST_DEDUCED_TYPENAME * removed usage of BOOST_NO_CXX11_HDR_INITIALIZER_LIST * removed usage of BOOST_NO_MEMBER_TEMPLATES * removed usage of BOOST_NO_SFINAE * removed leftover pp line * removed usage of BOOST_NO_MEMBER_TEMPLATE_FRIENDS * removed usage of BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP * removed usage of BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL * removed usage of BOOST_NO_CXX11_HDR_TYPE_TRAITS * removed usage of BOOST_NO_CXX11_HDR_RANDOM * removed usage of BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS * removed usage of BOOST_NO_CXX11_DECLTYPE * removed workarounds for pre-C++11 compilers * updated dependencies * removed usage of BOOST_MULTI_INDEX_MEMBER and similar in examples * updated docs * added C++11 badge * updated as per Alexander Grund's review * editorial * removed unneeded #includes
117 lines
3.1 KiB
C++
117 lines
3.1 KiB
C++
/* Boost.MultiIndex serialization tests template.
|
|
*
|
|
* Copyright 2003-2025 Joaquin M Lopez Munoz.
|
|
* 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 <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
|
|
#include <boost/archive/text_oarchive.hpp>
|
|
#include <boost/archive/text_iarchive.hpp>
|
|
#include <boost/detail/lightweight_test.hpp>
|
|
#include "pre_multi_index.hpp"
|
|
#include <boost/multi_index_container.hpp>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <vector>
|
|
|
|
#if defined(BOOST_MULTI_INDEX_ENABLE_MPL_SUPPORT)
|
|
#include <boost/mpl/size.hpp>
|
|
#else
|
|
#include <boost/mp11/list.hpp>
|
|
#endif
|
|
|
|
template<int N>
|
|
struct all_indices_equal_helper
|
|
{
|
|
template<class MultiIndexContainer>
|
|
static bool compare(
|
|
const MultiIndexContainer& m1,const MultiIndexContainer& m2)
|
|
{
|
|
if(!(boost::multi_index::get<N>(m1)==boost::multi_index::get<N>(m2))){
|
|
return false;
|
|
}
|
|
return all_indices_equal_helper<N-1>::compare(m1,m2);
|
|
}
|
|
};
|
|
|
|
template<>
|
|
struct all_indices_equal_helper<0>
|
|
{
|
|
template<class MultiIndexContainer>
|
|
static bool compare(
|
|
const MultiIndexContainer&,const MultiIndexContainer&)
|
|
{
|
|
return true;
|
|
}
|
|
};
|
|
|
|
template<class MultiIndexContainer>
|
|
bool all_indices_equal(
|
|
const MultiIndexContainer& m1,const MultiIndexContainer& m2)
|
|
{
|
|
#if defined(BOOST_MULTI_INDEX_ENABLE_MPL_SUPPORT)
|
|
BOOST_STATIC_CONSTANT(int,
|
|
N=boost::mpl::size<
|
|
typename MultiIndexContainer::index_type_list>::value);
|
|
#else
|
|
BOOST_STATIC_CONSTANT(int,
|
|
N=boost::mp11::mp_size<
|
|
typename MultiIndexContainer::index_type_list>::value);
|
|
#endif
|
|
|
|
return all_indices_equal_helper<N-1>::compare(m1,m2);
|
|
}
|
|
|
|
template<class MultiIndexContainer>
|
|
void test_serialization(const MultiIndexContainer& m)
|
|
{
|
|
typedef typename MultiIndexContainer::iterator iterator;
|
|
typedef typename MultiIndexContainer::const_iterator const_iterator;
|
|
|
|
std::ostringstream oss;
|
|
{
|
|
boost::archive::text_oarchive oa(oss);
|
|
oa<<m;
|
|
|
|
std::vector<const_iterator> its(m.size());
|
|
const_iterator it_end=m.end();
|
|
for(const_iterator it=m.begin();it!=it_end;++it){
|
|
its.push_back(it);
|
|
oa<<const_cast<const const_iterator&>(its.back());
|
|
}
|
|
oa<<const_cast<const const_iterator&>(it_end);
|
|
}
|
|
|
|
MultiIndexContainer m2;
|
|
std::istringstream iss(oss.str());
|
|
boost::archive::text_iarchive ia(iss);
|
|
ia>>m2;
|
|
BOOST_TEST(all_indices_equal(m,m2));
|
|
|
|
iterator it_end=m2.end();
|
|
for(iterator it=m2.begin();it!=it_end;++it){
|
|
iterator it2;
|
|
ia>>it2;
|
|
BOOST_TEST(it==it2);
|
|
|
|
/* exercise safe mode with this (unchecked) iterator */
|
|
BOOST_TEST(*it==*it2);
|
|
m2.erase(it,it2);
|
|
m2.erase(it2,it2);
|
|
m2.erase(it2,it);
|
|
iterator it3(++it2);
|
|
iterator it4;
|
|
it4=--it2;
|
|
BOOST_TEST(it==it4);
|
|
BOOST_TEST(it==boost::multi_index::project<0>(m2,it4));
|
|
}
|
|
iterator it2;
|
|
ia>>it2;
|
|
BOOST_TEST(it_end==it2);
|
|
BOOST_TEST(it_end==boost::multi_index::project<0>(m2,it2));
|
|
}
|