Skip to content

Add a trait for h5_compound #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions c++/h5/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions c++/h5/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ namespace h5 {
* @{
*/

template <typename T>
constexpr bool is_h5_compound = false;
namespace detail {

// Map a C++ type to an HDF5 type (specializations are in object.cpp).
Expand Down
12 changes: 8 additions & 4 deletions c++/h5/scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace h5 {
* @param x Scalar value to be written.
*/
template <typename T>
void h5_write(group g, std::string const &name, T const &x) H5_REQUIRES(std::is_arithmetic_v<T> or is_complex_v<T> or std::is_same_v<T, dcplx_t>) {
requires(std::is_arithmetic_v<T> or is_complex_v<T> or std::is_same_v<T, dcplx_t> or is_h5_compound<T>)
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);
}

Expand All @@ -82,7 +83,8 @@ namespace h5 {
* @param x Scalar variable to be read into.
*/
template <typename T>
void h5_read(group g, std::string const &name, T &x) H5_REQUIRES(std::is_arithmetic_v<T> or is_complex_v<T> or std::is_same_v<T, dcplx_t>) {
requires(std::is_arithmetic_v<T> or is_complex_v<T> or std::is_same_v<T, dcplx_t> or is_h5_compound<T>)
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<T>) {
if (g.has_subgroup(name)) {
Expand Down Expand Up @@ -122,7 +124,8 @@ namespace h5 {
* @param x Scalar value to be written.
*/
template <typename T>
void h5_write_attribute(object obj, std::string const &name, T const &x) H5_REQUIRES(std::is_arithmetic_v<T> or is_complex_v<T>) {
requires(std::is_arithmetic_v<T> or is_complex_v<T> or is_h5_compound<T>)
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));
}

Expand All @@ -137,7 +140,8 @@ namespace h5 {
* @param x Scalar variable to be read into.
*/
template <typename T>
void h5_read_attribute(object obj, std::string const &name, T &x) H5_REQUIRES(std::is_arithmetic_v<T> or is_complex_v<T>) {
requires(std::is_arithmetic_v<T> or is_complex_v<T> or is_h5_compound<T>)
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));
}

Expand Down
Loading