From 3be2ae868746f2fc09f69e667e18b838cef82be9 Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Fri, 19 May 2023 02:34:39 +0200 Subject: Initial commit with copying the unit lib --- src/kelunit/unit_print.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/kelunit/unit_print.h (limited to 'src/kelunit/unit_print.h') diff --git a/src/kelunit/unit_print.h b/src/kelunit/unit_print.h new file mode 100644 index 0000000..0f3cb72 --- /dev/null +++ b/src/kelunit/unit_print.h @@ -0,0 +1,55 @@ +#include "./unit.h" + +#include + + +namespace std { +template +inline ostream& operator<<(ostream& o, const kelun::unit_base& ele){ + o< +struct unit_print_impl { + static_assert(is_always_false, "Template type not supported"); +}; + +template +struct unit_print_impl,unit_base...> { + static std::ostream& print(std::ostream& o){ + + unit_base element; + + std::ostream& o_ret = o << element; + + if constexpr (sizeof...(UnitTL) > 0){ + std::ostream& o_ret_next = o_ret << ' ' << '*' << ' '; + return unit_print_impl...>::print(o_ret_next); + } + + return o_ret<<']'; + } +}; +} + +namespace std { + +template +inline ostream& operator<<(ostream& o, const kelun::unit& unit); + +template +inline ostream& operator<<(ostream& o, const kelun::unit...>& unit){ + o << unit.data(); + if constexpr (sizeof...(UnitT) > 0) { + auto& o_ret = o << ' '<<'['; + return kelun::unit_print_impl...>::print(o_ret); + } + return o; +} +} -- cgit v1.2.3