Skip to content

Commit

Permalink
Added custom fmt formatters for h5pp::varr_t and h5pp::vstr_t
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAce committed Sep 2, 2023
1 parent 1f7f081 commit af59592
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 15 additions & 1 deletion include/h5pp/details/h5ppVarr.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,18 @@ namespace h5pp::type::sfinae {

template<typename T>
inline constexpr bool is_or_has_varr_v = is_varr_v<T> or has_varr_v<T>;
}
}


#if defined(H5PP_USE_FMT) && defined(FMT_FORMAT_H_)

// Add a custom fmt::formatter for h5pp::varr_t
template<typename T, typename Char>
struct fmt::formatter<h5pp::varr_t<T>, Char, typename::std::enable_if_t<std::is_arithmetic_v<T>>::value> : fmt::formatter<std::vector<T>, Char> {
//template <typename T, typename=std::enable_if_t<std::is_arithmetic_v<T>>::value>
//struct fmt::formatter<h5pp::varr_t<T>>: formatter<std::vector<T>> {
auto format(const h5pp::varr_t<T> & v, format_context& ctx) const{
return fmt::formatter<std::vector<T>>::format(std::vector<T>(v.begin(), v.end()), ctx);
}
};
#endif
12 changes: 11 additions & 1 deletion include/h5pp/details/h5ppVstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,14 @@ namespace h5pp::type::sfinae {

template<typename T>
inline constexpr bool is_or_has_vstr_v = is_vstr_v<T> or has_vstr_v<T>;
}
}


#if defined(H5PP_USE_FMT) && defined(FMT_FORMAT_H_)
// Add a custom fmt::formatter for h5pp::vstr_t
template <> struct fmt::formatter<h5pp::vstr_t>: formatter<string_view> {
auto format(const h5pp::vstr_t &s, format_context& ctx) const{
return fmt::formatter<string_view>::format(s.c_str(), ctx);
}
};
#endif

0 comments on commit af59592

Please sign in to comment.