#include <h5cpp/all>
#include <iostream>
#include <list>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
template <class Fn>
static void try_block(const char* label, Fn&& fn) {
try { fn(); }
} catch (...) {
std::cout <<
"✘ failed " << label <<
" (unknown exception)\n";
}
}
int main() {
auto check = [](const char* label, bool ok) {
std::cout << (ok ?
"✔ ok " :
"✘ failed") <<
" " << label <<
"\n";
};
try_block("std::tuple<int,double> scalar round-trip", [&]() {
std::cout <<
" tuple<int,double> = " << back <<
"\n";
check("std::tuple<int,double> scalar round-trip", back == t);
});
std::cout <<
"◇ na std::tuple<..., std::string> scalar (layout mismatch: std::string in compound)\n";
try_block("std::vector<std::tuple<int,double>>(4) round-trip", [&]() {
std::cout <<
" vector<tuple<int,double>> = " << back <<
"\n";
check("std::vector<std::tuple<int,double>>(4) round-trip", back == v);
});
try_block("std::list<std::tuple<int,double>>(3) round-trip", [&]() {
std::cout <<
" list<tuple<int,double>> = " << back <<
"\n";
check("std::list<std::tuple<int,double>>(3) round-trip", back == l);
});
try_block("std::pair<int, double> scalar round-trip", [&]() {
std::cout <<
" pair<int,double> = " << back <<
"\n";
check("std::pair<int, double> scalar round-trip", back == p);
});
try_block("std::vector<std::pair<int,double>>(5) round-trip", [&]() {
std::vector<std::pair<int, double>> v = {{1, 0.5}, {2, 1.5}, {3, 2.5}, {4, 3.5}, {5, 4.5}};
std::cout <<
" vector<pair<int,double>> = " << back <<
"\n";
check("std::vector<std::pair<int,double>>(5) round-trip", back == v);
});
return 0;
}
h5::at_t create(const hid_t &parent, const std::string &path, args_t &&... args)
Create a new attribute of element type T on a parent HDF5 object.
Definition H5Acreate.hpp:100
T aread(const hid_t &ds, const std::string &name, const h5::acpl_t &acpl=h5::default_acpl)
Read an attribute by name and return its value as type T.
Definition H5Aread.hpp:76
std::enable_if_t<!std::is_same_v< T, char ** >, void > read(const h5::ds_t &ds, T *ptr, args_t &&... args)
Read elements from an open HDF5 dataset into caller-allocated memory.
Definition H5Dread.hpp:56
h5::gr_t write(const LOC &parent, const std::string &path, const T &src)
Write a sparse matrix or vector as a CSC group.
Definition H5Dsparse.hpp:185