refactor: dimension_symbol and unit_symbol refactored to use a variable template for caching result

This commit is contained in:
Mateusz Pusz
2024-11-16 21:59:40 +01:00
parent daf4b1cc5c
commit 658c0950f8
2 changed files with 4 additions and 8 deletions

View File

@@ -301,9 +301,7 @@ MP_UNITS_EXPORT template<dimension_symbol_formatting fmt, typename CharT, Dimens
} }
template<dimension_symbol_formatting fmt, typename CharT, Dimension D> template<dimension_symbol_formatting fmt, typename CharT, Dimension D>
struct dimension_symbol_result { constexpr auto dimension_symbol_result = dimension_symbol_impl<fmt, CharT>(D{});
static constexpr auto value = dimension_symbol_impl<fmt, CharT>(D{});
};
} // namespace detail } // namespace detail
@@ -312,7 +310,7 @@ MP_UNITS_EXPORT template<dimension_symbol_formatting fmt = dimension_symbol_form
Dimension D> Dimension D>
[[nodiscard]] consteval std::string_view dimension_symbol(D) [[nodiscard]] consteval std::string_view dimension_symbol(D)
{ {
return detail::dimension_symbol_result<fmt, CharT, D>::value.view(); return detail::dimension_symbol_result<fmt, CharT, D>.view();
} }
} // namespace mp_units } // namespace mp_units

View File

@@ -904,9 +904,7 @@ MP_UNITS_EXPORT template<unit_symbol_formatting fmt, typename CharT, Unit U>
} }
template<unit_symbol_formatting fmt, typename CharT, Unit U> template<unit_symbol_formatting fmt, typename CharT, Unit U>
struct unit_symbol_result { constexpr auto unit_symbol_result = unit_symbol_impl<fmt, CharT>(U{});
static constexpr auto value = unit_symbol_impl<fmt, CharT>(U{});
};
} // namespace detail } // namespace detail
@@ -914,7 +912,7 @@ struct unit_symbol_result {
MP_UNITS_EXPORT template<unit_symbol_formatting fmt = unit_symbol_formatting{}, typename CharT = char, Unit U> MP_UNITS_EXPORT template<unit_symbol_formatting fmt = unit_symbol_formatting{}, typename CharT = char, Unit U>
[[nodiscard]] consteval std::string_view unit_symbol(U) [[nodiscard]] consteval std::string_view unit_symbol(U)
{ {
return detail::unit_symbol_result<fmt, CharT, U>::value.view(); return detail::unit_symbol_result<fmt, CharT, U>.view();
} }
} // namespace mp_units } // namespace mp_units