From 700cde2d499742160deb361f42b7e861ae1db8ed Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Mon, 29 Jul 2024 14:18:30 +0200 Subject: Renaming to new standard --- c++/unit_print.hpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 c++/unit_print.hpp (limited to 'c++/unit_print.hpp') diff --git a/c++/unit_print.hpp b/c++/unit_print.hpp new file mode 100644 index 0000000..4d9187b --- /dev/null +++ b/c++/unit_print.hpp @@ -0,0 +1,55 @@ +#include "./unit.h" + +#include + + +namespace std { +template +inline ostream& operator<<(ostream& o, const kel::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 kel::unit& unit); + +template +inline ostream& operator<<(ostream& o, const kel::unit...>& unit){ + o << unit.data(); + if constexpr (sizeof...(UnitT) > 0) { + auto& o_ret = o << ' '<<'['; + return kel::unit_print_impl...>::print(o_ret); + } + return o; +} +} -- cgit v1.2.3