Skip to content

Commit

Permalink
Merge pull request USCiLab#355 from drivehappy/develop
Browse files Browse the repository at this point in the history
Fix bitset loading when bits are already set.
  • Loading branch information
AzothAmmo authored Oct 28, 2016
2 parents d27cc33 + 34bb0d9 commit 195c0bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/cereal/types/bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ namespace cereal
std::uint8_t chunk = 0;
std::uint8_t mask = 0;

bits.reset();

// Load one chunk at a time, rotating through the chunk
// to set bits in the bitset
for( std::size_t i = 0; i < N; ++i )
Expand Down
6 changes: 6 additions & 0 deletions unittests/bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void test_bitset()
std::bitset<65> o_bit65( rng65() );
std::bitset<256> o_bit256( rng256() );
std::bitset<512> o_bit512( rng512() );
std::bitset<32> o_bit32_low( 0 );

std::ostringstream os;
{
Expand All @@ -53,12 +54,14 @@ void test_bitset()
oar(o_bit65);
oar(o_bit256);
oar(o_bit512);
oar(o_bit32_low);
}

std::bitset<32> i_bit32;
std::bitset<65> i_bit65;
std::bitset<256> i_bit256;
std::bitset<512> i_bit512;
std::bitset<32> i_bit32_low( 0xffffffff );

std::istringstream is(os.str());
{
Expand All @@ -68,12 +71,15 @@ void test_bitset()
iar(i_bit65);
iar(i_bit256);
iar(i_bit512);
iar(i_bit32_low);
}

BOOST_CHECK_EQUAL( o_bit32, i_bit32 );
BOOST_CHECK_EQUAL( o_bit65, i_bit65 );
BOOST_CHECK_EQUAL( o_bit256, i_bit256 );
BOOST_CHECK_EQUAL( o_bit512, i_bit512 );

BOOST_CHECK_EQUAL( o_bit32_low, i_bit32_low );
}
}

Expand Down

0 comments on commit 195c0bf

Please sign in to comment.