How to check whether iterators form a contiguous memory zone?
- by Vincent
I currently have the following function to read an array or a vector of raw data (_readStream is a std::ifstream) :
template<typename IteratorType>
inline bool MyClass::readRawData(
const IteratorType& first,
const IteratorType& last,
typename std::iterator_traits<IteratorType>::iterator_category* = nullptr
)
{
_readStream.read(reinterpret_cast<char*>(&*first), (last-first)*sizeof(*first));
return _readStream.good();
}
First question : does this function seem ok for you ?
As we read directly a block of memory, it will only work if the memory block from first to last is contiguous in memory. How to check that ?