#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 ) { size_t const dataSize = std::addressof(vector.back()) - std::addressof(vector.front()) + 1; ar & vector.size(); // number of elements ar & dataSize; // size of data (may be larger due to allocator strategy) ar.save_binary( vector.data(), dataSize * sizeof(T) ); // 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 ) { size_t vectorSize; size_t dataSize; ar & vectorSize; ar & dataSize; vector.resize( vectorSize ); ar.load_binary( vector.data(), dataSize * sizeof(T)); } //! Serialization for non-arithmetic (and bool) vector types to binary template typename std::enable_if::value || std::is_same::value, void>::type save( BinaryOutputArchive & ar, std::vector const & vector ) { ar & vector.size(); // number of elements for( auto it = vector.begin(), end = vector.end(); it != end; ++it ) ar & (*it); } //! Serialization for non-arithmetic (and bool) vector types to binary (non-const version) template typename std::enable_if::value || std::is_same::value, void>::type save( BinaryOutputArchive & ar, std::vector & vector ) { ar & vector.size(); // number of elements for( auto it = vector.begin(), end = vector.end(); it != end; ++it ) ar & (*it); } //! Serialization for non-arithmetic (and bool) vector types from binary template typename std::enable_if::value || std::is_same::value, void>::type 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_