Closed sgn closed 1 year ago
I see the same thing with Boost 1.81 using Clang 15.0.0 in the VxWorks port. Is there any reason to expect that for the unordered containers case, the serialized-then-deserialized version of the collection would have its elements in the same order as the original collection?
Possible alternative test_serialization_unordered_set_helper() implementation:
template< class Cont, class OArchive, class IArchive >
void test_serialization_unordered_set_helper()
{
Cont vec;
set_capacity<Cont>()( vec );
add( vec, new Base( -1 ), 0u );
add( vec, new Derived( 1 ), 1u );
BOOST_CHECK_EQUAL( vec.size(), 2u );
std::string fn = std::tmpnam( 0 );
{
std::ofstream ofs( fn.c_str() );
OArchive oa(ofs);
oa << boost::serialization::make_nvp( "container", as_const(vec) );
}
Cont vec2;
{
std::ifstream ifs( fn.c_str(), std::ios::binary );
IArchive ia(ifs);
ia >> boost::serialization::make_nvp( "container", vec2 );
}
std::remove( fn.c_str() );
BOOST_CHECK_EQUAL( vec.size(), vec2.size() );
// Note, as unordered containers, vec2 may have its elements in a different
// order than vec.
typename Cont::iterator it = vec2.begin();
int iFirst = (*it).i;
int iSecond = (*++vec2.begin()).i;
if (iFirst == -1) {
BOOST_CHECK_EQUAL (iSecond, 0);
++it;
} else {
BOOST_CHECK_EQUAL (iFirst, 0);
BOOST_CHECK_EQUAL (iSecond, -1);
}
Derived* d = dynamic_cast<Derived*>( &*it );
BOOST_CHECK_EQUAL( d->i2, 1 );
}