#include "tiny_containers.hpp"
#include <h5cpp/all>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
static constexpr const char* glyph(bool b) { return b ? "✔" : "✘"; }
static const char* storage_name(h5::meta::storage_representation_t s) {
using sr = h5::meta::storage_representation_t;
switch (s) {
case sr::unsupported: return "unsupported";
case sr::scalar: return "scalar";
case sr::c_array: return "c_array";
case sr::linear_value_dataset: return "linear_value_dataset";
case sr::key_value_dataset: return "key_value_dataset";
case sr::ragged_vlen_dataset: return "ragged_vlen_dataset";
case sr::fixed_inner_extent_dataset: return "fixed_inner_extent_dataset";
case sr::vlen_text_dataset: return "vlen_text_dataset";
}
return "?";
}
template <class T>
static void trait_card(const char* label) {
using U = std::remove_cv_t<std::remove_reference_t<T>>;
namespace m = h5::meta;
std::cout <<
" " << glyph(m::has_iterator<U>::value) <<
" has_iterator\n";
std::cout <<
" " << glyph(m::has_value_type<U>::value) <<
" has_value_type\n";
std::cout <<
" " << glyph(m::has_data<U>::value) <<
" has_data\n";
std::cout <<
" " << glyph(m::has_size<U>::value) <<
" has_size\n";
std::cout <<
" " << glyph(m::is_sequential_like<U>::value) <<
" is_sequential_like\n";
std::cout <<
" " << glyph(m::is_set_like<U>::value) <<
" is_set_like (has key_type, no mapped_type)\n";
std::cout <<
" " << glyph(m::is_map_like<U>::value) <<
" is_map_like (has key_type + mapped_type)\n";
<< storage_name(m::storage_representation_v<U>) << "\n";
}
int main() {
std::cout <<
"h5cpp detection-idiom dispatch — custom container demo\n";
std::cout <<
"======================================================\n";
std::cout <<
"\n[Layer-1: capability detection (Walter Brown N4502)]\n";
trait_card<tiny::vec<int>> ("tiny::vec<int>");
trait_card<tiny::flist<int>> ("tiny::flist<int>");
trait_card<tiny::set<int>> ("tiny::set<int>");
trait_card<tiny::dict<int, double>> ("tiny::dict<int,double>");
std::cout <<
"\n[Layer-2: write via custom container, read as std::]\n";
auto fd =
h5::create(
"detected.h5", H5F_ACC_TRUNC);
{
tiny::vec<int> v{1, 2, 3, 4, 5};
std::cout <<
" tiny::vec<int> wrote " << v.size()
<< " back as tiny::vec: " << view << "\n";
}
{
tiny::flist<int> l{10, 20, 30, 40};
std::cout <<
" tiny::flist<int> wrote " << l.size()
<< " back as std::vector: " << back << "\n";
}
{
tiny::set<int> s{3, 1, 4, 1, 5, 9, 2, 6};
std::cout <<
" tiny::set<int> wrote " << s.size()
<< " back as std::set: " << back << "\n";
}
{
tiny::dict<int, double> d{{1, 1.5}, {2, 2.5}, {3, 3.5}};
std::cout <<
" tiny::dict<int,d> wrote " << d.size()
<< " back as std::map: " << back << "\n";
}
" Read for contiguous vector-shape is now structural: any T with .data() +\n"
" .size() + T(size_t) ctor round-trips into T itself (see tiny::vec above).\n"
" Set-like / map-like / iterator-only customs still read back via the std::\n"
" counterpart — the iterator-staging and kv_t-compound paths construct\n"
" through range-ctor / insert, which doesn't have a structural equivalent.\n";
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