mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 04:44:27 +02:00
refactor: dimension_symbol
and unit_symbol
refactored to use a variable template for caching result
This commit is contained in:
@@ -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
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user