Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/cereal/types/concepts/pair_associative_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace cereal

map.clear();

auto hint = map.begin();
auto hint = map.end();
for( size_t i = 0; i < size; ++i )
{
typename Map<Args...>::key_type key;
Expand All @@ -66,6 +66,7 @@ namespace cereal
#else // NOT CEREAL_OLDER_GCC
hint = map.emplace_hint( hint, std::move( key ), std::move( value ) );
#endif // NOT CEREAL_OLDER_GCC
hint = map.end();
}
}
} // namespace cereal
Expand Down
3 changes: 2 additions & 1 deletion include/cereal/types/set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace cereal

set.clear();

auto hint = set.begin();
auto hint = set.end();
for( size_type i = 0; i < size; ++i )
{
typename SetT::key_type key;
Expand All @@ -67,6 +67,7 @@ namespace cereal
#else // NOT CEREAL_OLDER_GCC
hint = set.emplace_hint( hint, std::move( key ) );
#endif // NOT CEREAL_OLDER_GCC
hint = set.end();
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions unittests/multimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,25 @@ TEST_SUITE_BEGIN("multimap");
TEST_CASE("binary_multimap")
{
test_multimap<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
test_multimap_equivalent_keys_order<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
}

TEST_CASE("portable_binary_multimap")
{
test_multimap<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
test_multimap_equivalent_keys_order<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
}

TEST_CASE("xml_multimap")
{
test_multimap<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
test_multimap_equivalent_keys_order<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
}

TEST_CASE("json_multimap")
{
test_multimap<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
test_multimap_equivalent_keys_order<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
}

TEST_SUITE_END();
30 changes: 30 additions & 0 deletions unittests/multimap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ void test_multimap()
}

#define MULTIMAP_CHECK(InMap, OutMap) \
CHECK_EQ( InMap.size(), OutMap.size() ); \
CHECK_UNARY( std::equal( InMap.begin(), InMap.end(), OutMap.begin() ) ); \
for( auto & pair : OutMap ) \
{ \
auto const count = InMap.count( pair.first ); \
Expand All @@ -126,4 +128,32 @@ void test_multimap()
}
}

template <class IArchive, class OArchive> inline
void test_multimap_equivalent_keys_order()
{
std::multimap<char, int> o_multimap;
o_multimap.emplace('a', 1);
o_multimap.emplace('a', 2);
o_multimap.emplace('a', 3);
o_multimap.emplace('b', 10);
o_multimap.emplace('b', 20);
o_multimap.emplace('b', 30);

std::ostringstream os;
{
OArchive oar(os);
oar(o_multimap);
}

std::multimap<char, int> i_multimap;
std::istringstream is(os.str());
{
IArchive iar(is);
iar(i_multimap);
}

CHECK_EQ(i_multimap.size(), o_multimap.size());
CHECK_UNARY(std::equal(i_multimap.begin(), i_multimap.end(), o_multimap.begin()));
}

#endif // CEREAL_TEST_MULTIMAP_H_
4 changes: 4 additions & 0 deletions unittests/multiset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,25 @@ TEST_SUITE_BEGIN("multiset");
TEST_CASE("binary_multiset")
{
test_multiset<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
test_multiset_equivalent_keys_order<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
}

TEST_CASE("portable_binary_multiset")
{
test_multiset<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
test_multiset_equivalent_keys_order<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
}

TEST_CASE("xml_multiset")
{
test_multiset<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
test_multiset_equivalent_keys_order<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
}

TEST_CASE("json_multiset")
{
test_multiset<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
test_multiset_equivalent_keys_order<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
}

TEST_SUITE_END();
37 changes: 37 additions & 0 deletions unittests/multiset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,68 @@ void test_multiset()
iar(i_esplmultiset);
}

CHECK_EQ( i_podmultiset.size(), o_podmultiset.size() );
CHECK_UNARY( std::equal( i_podmultiset.begin(), i_podmultiset.end(), o_podmultiset.begin() ) );
for(auto const & p : i_podmultiset)
{
CHECK_EQ(o_podmultiset.count(p), i_podmultiset.count(p));
}

CHECK_EQ( i_isermultiset.size(), o_isermultiset.size() );
CHECK_UNARY( std::equal( i_isermultiset.begin(), i_isermultiset.end(), o_isermultiset.begin() ) );
for(auto const & p : i_isermultiset)
{
CHECK_EQ(o_isermultiset.count(p), i_isermultiset.count(p));
}

CHECK_EQ( i_isplmultiset.size(), o_isplmultiset.size() );
CHECK_UNARY( std::equal( i_isplmultiset.begin(), i_isplmultiset.end(), o_isplmultiset.begin() ) );
for(auto const & p : i_isplmultiset)
{
CHECK_EQ(o_isplmultiset.count(p), i_isplmultiset.count(p));
}

CHECK_EQ( i_esermultiset.size(), o_esermultiset.size() );
CHECK_UNARY( std::equal( i_esermultiset.begin(), i_esermultiset.end(), o_esermultiset.begin() ) );
for(auto const & p : i_esermultiset)
{
CHECK_EQ(o_esermultiset.count(p), i_esermultiset.count(p));
}

CHECK_EQ( i_esplmultiset.size(), o_esplmultiset.size() );
CHECK_UNARY( std::equal( i_esplmultiset.begin(), i_esplmultiset.end(), o_esplmultiset.begin() ) );
for(auto const & p : i_esplmultiset)
{
CHECK_EQ(o_esplmultiset.count(p), i_esplmultiset.count(p));
}
}
}

template <class IArchive, class OArchive> inline
void test_multiset_equivalent_keys_order()
{
std::multiset<int> o_multiset;
o_multiset.emplace(1);
o_multiset.emplace(1);
o_multiset.emplace(1);
o_multiset.emplace(2);
o_multiset.emplace(2);

std::ostringstream os;
{
OArchive oar(os);
oar(o_multiset);
}

std::multiset<int> i_multiset;
std::istringstream is(os.str());
{
IArchive iar(is);
iar(i_multiset);
}

CHECK_EQ(i_multiset.size(), o_multiset.size());
CHECK_UNARY(std::equal(i_multiset.begin(), i_multiset.end(), o_multiset.begin()));
}

#endif // CEREAL_TEST_MULTISET_H_