From 880528e5ca93da0159a3591582c7c125d461d19b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 18 Oct 2019 22:34:43 +0200 Subject: [PATCH] Compile-time performance of printing a prefix improved --- src/include/units/format.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/include/units/format.h b/src/include/units/format.h index 4fde18a3..6728eeb3 100644 --- a/src/include/units/format.h +++ b/src/include/units/format.h @@ -47,16 +47,17 @@ namespace units { void print_prefix_or_ratio(std::basic_ostream& os) { if constexpr(Ratio::num != 1 || Ratio::den != 1) { - using prefix = downcast_target>; + if(!std::same_as) { + using prefix = downcast_target>; - if constexpr(!std::same_as>) { - // print as a prefixed unit - os << prefix::symbol; - } - else { - // print as a ratio of the coherent unit - print_ratio(os); + if constexpr(!std::same_as>) { + // print as a prefixed unit + os << prefix::symbol; + return; + } } + // print as a ratio of the coherent unit + print_ratio(os); } }