#ifndef CEREAL_BINARY_ARCHIVE_VECTOR_HPP_ #define CEREAL_BINARY_ARCHIVE_VECTOR_HPP_ #include #include namespace cereal { //! Serialization for std::vectors of arithmetic (but not bool) types to binary template typename std::enable_if::value && !std::is_same::value, void>::type save( BinaryOutputArchive & ar, std::vector const & vector ) { std::cout << "Saving vector (arithmetic)" << std::endl; const size_t dataSize = std::addressof(vector.back()) - std::addressof(vector.front()); ar & vector.size(); // number of elements ar & dataSize; // size of data (may be larger due to allocator strategy) ar.save_binary( array.data(), size ); // actual data } //! Serialization for std::vectors of arithmetic (but not bool) types to binary template typename std::enable_if::value && !std::is_same::value, void>::type load( BinaryInputArchive & ar, std::vector & vector ) { std::cout << "Loading vector (arithmetic)" << std::endl; size_t dataSize; size_t vectorSize; ar & vectorSize; ar & dataSize; vector.resize( vectorSize ); ar.load_binary( vector.data(), dataSize ); } //! Serialization for all other vector types template void save( BinaryOutputArchive & ar, std::vector const & vector ) { std::cout << "Saving vector" << std::endl; ar & vector.size(); // number of elements for( auto it = vector.begin(), end = vector.end(); it != end; ++it ) ar & (*it); } //! Serialization for std::vector to binary template void load( BinaryInputArchive & ar, std::vector & vector ) { size_t size; ar & size; vector.resize( size ); for( auto it = vector.begin(), end = vector.end(); it != end; ++it ) ar & (*it); } } // namespace cereal #endif // CEREAL_BINARY_ARCHIVE_VECTOR_HPP_