diff --git a/c++/h5/macros.hpp b/c++/h5/macros.hpp index 9a9f613..10465fa 100644 --- a/c++/h5/macros.hpp +++ b/c++/h5/macros.hpp @@ -30,14 +30,6 @@ #define H5_AS_STRING(...) H5_AS_STRING2(__VA_ARGS__) #define H5_AS_STRING2(...) #__VA_ARGS__ -// ---------------- Requires ---------------- - -#ifdef __clang__ -#define H5_REQUIRES(...) __attribute__((enable_if(__VA_ARGS__, H5_AS_STRING2(__VA_ARGS__)))) -#elif __GNUC__ -#define H5_REQUIRES(...) requires(__VA_ARGS__) -#endif - // ---------------- Print ---------------- #define H5_PRINT(X) std::cerr << H5_AS_STRING(X) << " = " << X << " at " << __FILE__ << ":" << __LINE__ << '\n' diff --git a/c++/h5/object.hpp b/c++/h5/object.hpp index 71907f5..d7f856e 100644 --- a/c++/h5/object.hpp +++ b/c++/h5/object.hpp @@ -138,6 +138,8 @@ namespace h5 { * @{ */ + template + constexpr bool is_h5_compound = false; namespace detail { // Map a C++ type to an HDF5 type (specializations are in object.cpp). diff --git a/c++/h5/scalar.hpp b/c++/h5/scalar.hpp index f630de6..314450d 100644 --- a/c++/h5/scalar.hpp +++ b/c++/h5/scalar.hpp @@ -67,7 +67,8 @@ namespace h5 { * @param x Scalar value to be written. */ template - void h5_write(group g, std::string const &name, T const &x) H5_REQUIRES(std::is_arithmetic_v or is_complex_v or std::is_same_v) { + requires(std::is_arithmetic_v or is_complex_v or std::is_same_v or is_h5_compound) + void h5_write(group g, std::string const &name, T const &x) { array_interface::write(g, name, array_interface::array_view_from_scalar(x), false); } @@ -82,7 +83,8 @@ namespace h5 { * @param x Scalar variable to be read into. */ template - void h5_read(group g, std::string const &name, T &x) H5_REQUIRES(std::is_arithmetic_v or is_complex_v or std::is_same_v) { + requires(std::is_arithmetic_v or is_complex_v or std::is_same_v or is_h5_compound) + void h5_read(group g, std::string const &name, T &x) { // backward compatibility to read complex values stored the old way (in a subgroup) if constexpr (is_complex_v) { if (g.has_subgroup(name)) { @@ -122,7 +124,8 @@ namespace h5 { * @param x Scalar value to be written. */ template - void h5_write_attribute(object obj, std::string const &name, T const &x) H5_REQUIRES(std::is_arithmetic_v or is_complex_v) { + requires(std::is_arithmetic_v or is_complex_v or is_h5_compound) + void h5_write_attribute(object obj, std::string const &name, T const &x) { array_interface::write_attribute(obj, name, array_interface::array_view_from_scalar(x)); } @@ -137,7 +140,8 @@ namespace h5 { * @param x Scalar variable to be read into. */ template - void h5_read_attribute(object obj, std::string const &name, T &x) H5_REQUIRES(std::is_arithmetic_v or is_complex_v) { + requires(std::is_arithmetic_v or is_complex_v or is_h5_compound) + void h5_read_attribute(object obj, std::string const &name, T &x) { array_interface::read_attribute(obj, name, array_interface::array_view_from_scalar(x)); }