From 4d68087eebc608343f2e90984b3e52972c3b220e Mon Sep 17 00:00:00 2001 From: Torsten Reuschel <89043237+unbtorsten@users.noreply.github.com> Date: Thu, 19 Oct 2023 10:22:27 -0300 Subject: [PATCH] Support for complex integral types (#828) Compilers seem to allow `std::complex`, officially as of C++23. Therefore, HighFive shouldn't prevent this usecase. --- include/highfive/bits/H5DataType_misc.hpp | 4 ++-- tests/unit/tests_high_five_easy.cpp | 26 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/highfive/bits/H5DataType_misc.hpp b/include/highfive/bits/H5DataType_misc.hpp index 934d5f5e5..01c4af410 100644 --- a/include/highfive/bits/H5DataType_misc.hpp +++ b/include/highfive/bits/H5DataType_misc.hpp @@ -300,8 +300,8 @@ class AtomicType>: public DataType { : DataType( CompoundType({{"r", create_datatype(), 0}, {"i", create_datatype(), sizeof(T)}}, sizeof(std::complex))) { - static_assert(std::is_floating_point::value, - "std::complex accepts only floating point numbers."); + static_assert(std::is_arithmetic::value, + "std::complex accepts only floating point and integral numbers."); } }; diff --git a/tests/unit/tests_high_five_easy.cpp b/tests/unit/tests_high_five_easy.cpp index 3a55d6801..e003c3234 100644 --- a/tests/unit/tests_high_five_easy.cpp +++ b/tests/unit/tests_high_five_easy.cpp @@ -61,31 +61,57 @@ TEST_CASE("H5Easy_scalar") { double a = 1.2345; int b = 12345; std::string c = "12345"; + std::complex d = std::complex(1.2345, -5.4321); + std::complex e = std::complex(12345, -54321); H5Easy::dump(file, "/path/to/a", a); H5Easy::dump(file, "/path/to/b", b); H5Easy::dump(file, "/path/to/c", c); H5Easy::dump(file, "/path/to/c", c, H5Easy::DumpMode::Overwrite); + H5Easy::dump(file, "/path/to/d", d); + H5Easy::dump(file, "/path/to/e", e); double a_r = H5Easy::load(file, "/path/to/a"); int b_r = H5Easy::load(file, "/path/to/b"); std::string c_r = H5Easy::load(file, "/path/to/c"); + std::complex d_r = H5Easy::load>(file, "/path/to/d"); + std::complex e_r = H5Easy::load>(file, "/path/to/e"); CHECK(a == a_r); CHECK(b == b_r); CHECK(c == c_r); + CHECK(d == d_r); + CHECK(e == e_r); } TEST_CASE("H5Easy_vector1d") { H5Easy::File file("h5easy_vector1d.h5", H5Easy::File::Overwrite); std::vector a = {1, 2, 3, 4, 5}; + std::vector> b = {std::complex(1, .1), + std::complex(2, -.4), + std::complex(3, .9), + std::complex(4, -.16), + std::complex(5, .25)}; + std::vector> c = {std::complex(1, -5), + std::complex(2, -4), + std::complex(3, -3), + std::complex(4, -2), + std::complex(5, -1)}; H5Easy::dump(file, "/path/to/a", a); + H5Easy::dump(file, "/path/to/b", b); + H5Easy::dump(file, "/path/to/c", c); std::vector a_r = H5Easy::load>(file, "/path/to/a"); + std::vector> b_r = + H5Easy::load>>(file, "/path/to/b"); + std::vector> c_r = + H5Easy::load>>(file, "/path/to/c"); CHECK(a == a_r); + CHECK(b == b_r); + CHECK(c == c_r); } TEST_CASE("H5Easy_vector2d") {