From: Daniel Garcia-Sanchez Date: Sun, 7 Oct 2018 11:29:35 +0000 (+0200) Subject: Use make_shared in get_hdf5_datatype() X-Git-Tag: v9.1.0-rc1~453^2~37 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06575e468bf8dc0c6d6f9914d8868efcf062377d;p=dealii.git Use make_shared in get_hdf5_datatype() --- diff --git a/source/base/hdf5.cc b/source/base/hdf5.cc index 62a6e7d49e..e6a86c0c55 100644 --- a/source/base/hdf5.cc +++ b/source/base/hdf5.cc @@ -37,6 +37,12 @@ namespace HDF5 // This function gives the HDF5 datatype corresponding to the C++ type. In // the case of std::complex types the HDF5 handlers are automatically freed // using the destructor of std::shared_ptr. + // std::shared_ptr is used instead of std::unique_ptr because the destructor + // of std::shared_ptr doesn't have to be defined in the template argument. + // In the other hand, the destructor of std::unique has to be defined in the + // template argument. Native types such as H5T_NATIVE_DOUBLE does not + // require a constructor, but compound types such as std::complex + // require a destructor to free the HDF5 resources. template std::shared_ptr get_hdf5_datatype() @@ -44,23 +50,19 @@ namespace HDF5 std::shared_ptr t_type; if (std::is_same::value) { - t_type = std::shared_ptr(new hid_t); - *t_type = H5T_NATIVE_FLOAT; + return std::make_shared(H5T_NATIVE_FLOAT); } else if (std::is_same::value) { - t_type = std::shared_ptr(new hid_t); - *t_type = H5T_NATIVE_DOUBLE; + return std::make_shared(H5T_NATIVE_DOUBLE); } else if (std::is_same::value) { - t_type = std::shared_ptr(new hid_t); - *t_type = H5T_NATIVE_INT; + return std::make_shared(H5T_NATIVE_INT); } else if (std::is_same::value) { - t_type = std::shared_ptr(new hid_t); - *t_type = H5T_NATIVE_UINT; + return std::make_shared(H5T_NATIVE_UINT); } else if (std::is_same>::value) { @@ -76,6 +78,7 @@ namespace HDF5 // imaginary [1] parts. H5Tinsert(*t_type, "r", 0, H5T_NATIVE_FLOAT); H5Tinsert(*t_type, "i", sizeof(float), H5T_NATIVE_FLOAT); + return t_type; } else if (std::is_same>::value) { @@ -91,11 +94,11 @@ namespace HDF5 // imaginary [1] parts. H5Tinsert(*t_type, "r", 0, H5T_NATIVE_DOUBLE); H5Tinsert(*t_type, "i", sizeof(double), H5T_NATIVE_DOUBLE); + return t_type; } - else - { - Assert(false, ExcInternalError()); - } + + // The function should not reach this point + Assert(false, ExcInternalError()); return t_type; }