#include <h5cpp/all>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
template <class C>
static bool same_map(const C& a, const C& b) {
if (a.size() != b.size()) return false;
using key_t = typename C::key_type;
using mapped_t = typename C::mapped_type;
auto cmp = [](const auto& x, const auto& y) {
if (x.first != y.first) return x.first < y.first;
return x.second < y.second;
};
return as == bs;
}
int main() {
auto check = [](const char* label, bool ok) {
std::cout << (ok ?
"✔ ok " :
"✘ failed") <<
" " << label <<
"\n";
};
{
std::cout <<
" map<int,double>(4) = " << back <<
"\n";
check("std::map<int, double> round-trip", back == m);
}
{
std::multimap<short, int> mm = {{1, 10}, {1, 11}, {2, 20}, {3, 30}, {3, 31}};
h5::write(fd,
"/maps/multimap_short_int", mm);
std::cout <<
" multimap<short,int>(5) = " << back <<
"\n";
check("std::multimap<short, int> round-trip", back == mm);
}
{
h5::write(fd,
"/maps/unordered_map_int_float", um);
std::cout <<
" u_map<int,float>(3) = " << back <<
"\n";
check("std::unordered_map<int, float> round-trip (key-cmp)", same_map(um, back));
}
{
std::unordered_multimap<int, int> umm = {{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}};
h5::write(fd,
"/maps/unordered_multimap", umm);
std::cout <<
" u_multimap<int,int>(5) = " << back <<
"\n";
check("std::unordered_multimap<int,int> round-trip (key-cmp)", same_map(umm, back));
}
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
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