diff --git a/opm/autodiff/BackupRestore.hpp b/opm/autodiff/BackupRestore.hpp index 0be1c3bd7..21262d9c2 100644 --- a/opm/autodiff/BackupRestore.hpp +++ b/opm/autodiff/BackupRestore.hpp @@ -86,11 +86,27 @@ namespace Opm { assert( int(size) == int(n) ); } + template + void readData(std::istream& stream, Container& container, size_t datasize) + { + stream.read( reinterpret_cast( container.data() ), datasize ); + } + + //We need to be careful with string, because string.data() returns something that + //"A program shall not alter any of the characters in this sequence." + template <> + void readData(std::istream& stream, std::string& string, size_t datasize) + { + std::vector raw_data(datasize); + readData(stream, raw_data, datasize); + string = std::string(raw_data.data(), datasize); + } + template void readContainerImpl( std::istream& stream, Container& container, const bool adjustSize ) { typedef typename Container :: value_type T; - unsigned int dataSize = 0; + size_t dataSize = 0; readValue( stream, dataSize ); if( adjustSize && dataSize > 0 ) { resizeContainer( container, dataSize/sizeof(T) ); @@ -103,7 +119,7 @@ namespace Opm { << dataSize << " " << (container.size() * sizeof( T )) ); } if( dataSize > 0 ) { - stream.read( (char *) container.data(), dataSize ); + readData(stream, container, dataSize); } }