diff --git a/include/highfive/bits/H5Attribute_misc.hpp b/include/highfive/bits/H5Attribute_misc.hpp index 7ad3869..6a160c5 100644 --- a/include/highfive/bits/H5Attribute_misc.hpp +++ b/include/highfive/bits/H5Attribute_misc.hpp @@ -68,6 +68,13 @@ inline T Attribute::read() const { template inline void Attribute::read(T& array) const { const DataSpace& mem_space = getMemSpace(); + auto dims = mem_space.getDimensions(); + + if (mem_space.getElementCount() == 0) { + details::inspector::prepare(array, dims); + return; + } + auto file_datatype = getDataType(); const details::BufferInfo buffer_info( file_datatype, @@ -81,12 +88,6 @@ inline void Attribute::read(T& array) const { << buffer_info.getMaxRank() << "(max)"; throw DataSpaceException(ss.str()); } - auto dims = mem_space.getDimensions(); - - if (mem_space.getElementCount() == 0) { - details::inspector::prepare(array, dims); - return; - } auto r = details::data_converter::get_reader(dims, array, file_datatype); read_raw(r.getPointer(), buffer_info.data_type); @@ -133,7 +134,6 @@ inline void Attribute::write(const T& buffer) { } auto file_datatype = getDataType(); - const details::BufferInfo buffer_info( file_datatype, [this]() -> std::string { return this->getName(); },