//! @internal template <class Archive, class SetT> inline void load( Archive & ar, SetT & set ) { size_t size; ar( make_size_tag( size ) ); set.clear(); auto hint = set.begin(); for( size_t i = 0; i < size; ++i ) { typename SetT::key_type key; ar( key ); hint = set.insert(hint, key ); } }
//! @internal template <class Archive, class SetT> inline void save( Archive & ar, SetT const & set ) { ar( make_size_tag( set.size() ) ); for( const auto & i : set ) ar( i ); }
//! @internal template <class Archive, class SetT> inline void load( Archive & ar, SetT & set ) { size_type size; ar( make_size_tag( size ) ); set.clear(); set.reserve( static_cast<std::size_t>( size ) ); for( size_type i = 0; i < size; ++i ) { typename SetT::key_type key; ar( key ); set.emplace( std::move( key ) ); } }
//! @internal template <class Archive, class SetT> inline void load( Archive & ar, SetT & set ) { size_type size; ar( make_size_tag( size ) ); set.clear(); set.reserve( size ); for( size_type i = 0; i < size; ++i ) { typename SetT::key_type key; ar( key ); set.insert( key ); } }
TEST(SortedVectorTypes, GrowthPolicy) { typedef sorted_vector_set<CountCopyCtor, std::less<CountCopyCtor>, std::allocator<CountCopyCtor>, OneAtATimePolicy> SetT; SetT a; for (int i = 0; i < 20; ++i) { a.insert(CountCopyCtor(i)); } check_invariant(a); SetT::iterator it = a.begin(); EXPECT_FALSE(it == a.end()); if (it != a.end()) { EXPECT_EQ(it->val_, 0); // 1 copy for the initial insertion, 19 more for reallocs on the // additional insertions. EXPECT_EQ(it->count_, 20); } std::list<CountCopyCtor> v; for (int i = 0; i < 20; ++i) { v.push_back(CountCopyCtor(20 + i)); } a.insert(v.begin(), v.end()); check_invariant(a); it = a.begin(); EXPECT_FALSE(it == a.end()); if (it != a.end()) { EXPECT_EQ(it->val_, 0); // Should be only 1 more copy for inserting this above range. EXPECT_EQ(it->count_, 21); } }