Turn get_value into free function

This commit is contained in:
Chip Hogg
2022-01-29 02:40:51 +00:00
parent d6eb25f07a
commit b36bc2b582
2 changed files with 27 additions and 24 deletions
+9 -6
View File
@@ -336,14 +336,9 @@ struct magnitude {
// The value of this magnitude, expressed in a given type.
template<typename T>
requires (std::is_floating_point_v<T> || (detail::is_integral(BPs) && ...))
requires (std::is_floating_point_v<T> || (std::is_integral_v<T> && is_magnitude_integral))
static constexpr T value = detail::checked_static_cast<T>(
(detail::compute_base_power<T>(BPs) * ...));
// Trying to satisfy MSVC 14...
template<typename T>
requires (std::is_floating_point_v<T> || (detail::is_integral(BPs) && ...))
constexpr T get_value() const { return magnitude::value<T>; }
};
// Implementation for Magnitude concept (below).
@@ -360,6 +355,14 @@ static constexpr bool is_magnitude<magnitude<BPs...>> = true;
template<typename T>
concept Magnitude = detail::is_magnitude<T>;
/**
* @brief Free-function access to the value of a Magnitude in a desired type.
*
* Can avoid the need for an unsightly `.template` keyword.
*/
template<typename T>
T get_value(Magnitude auto m) { return m.template value<T>; }
/**
* @brief Convert any positive integer to a Magnitude.
*