forked from mpusz/mp-units
merge branch master
This commit is contained in:
@@ -53,12 +53,12 @@ std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>&
|
||||
} // namespace geographic
|
||||
|
||||
template<>
|
||||
struct STD_FMT::formatter<geographic::msl_altitude> : formatter<geographic::msl_altitude::quantity_type> {
|
||||
struct UNITS_STD_FMT::formatter<geographic::msl_altitude> : formatter<geographic::msl_altitude::quantity_type> {
|
||||
template<typename FormatContext>
|
||||
auto format(const geographic::msl_altitude& a, FormatContext& ctx)
|
||||
{
|
||||
formatter<geographic::msl_altitude::quantity_type>::format(a.absolute(), ctx);
|
||||
return STD_FMT::format_to(ctx.out(), " AMSL");
|
||||
return UNITS_STD_FMT::format_to(ctx.out(), " AMSL");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -145,21 +145,21 @@ class std::numeric_limits<geographic::longitude<T>> : public numeric_limits<T> {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct STD_FMT::formatter<geographic::latitude<T>> : formatter<T> {
|
||||
struct UNITS_STD_FMT::formatter<geographic::latitude<T>> : formatter<T> {
|
||||
template<typename FormatContext>
|
||||
auto format(geographic::latitude<T> lat, FormatContext& ctx)
|
||||
{
|
||||
STD_FMT::format_to(ctx.out(), "{}", lat > geographic::latitude<T>::zero() ? 'N' : 'S');
|
||||
UNITS_STD_FMT::format_to(ctx.out(), "{}", lat > geographic::latitude<T>::zero() ? 'N' : 'S');
|
||||
return formatter<T>::format(lat > geographic::latitude<T>::zero() ? lat.number() : -lat.number(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct STD_FMT::formatter<geographic::longitude<T>> : formatter<T> {
|
||||
struct UNITS_STD_FMT::formatter<geographic::longitude<T>> : formatter<T> {
|
||||
template<typename FormatContext>
|
||||
auto format(geographic::longitude<T> lon, FormatContext& ctx)
|
||||
{
|
||||
STD_FMT::format_to(ctx.out(), "{}", lon > geographic::longitude<T>::zero() ? 'E' : 'W');
|
||||
UNITS_STD_FMT::format_to(ctx.out(), "{}", lon > geographic::longitude<T>::zero() ? 'E' : 'W');
|
||||
return formatter<T>::format(lon > geographic::longitude<T>::zero() ? lon.number() : -lon.number(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -26,21 +26,29 @@
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
#include <mp-units/customization_points.h>
|
||||
#include <algorithm>
|
||||
#include <concepts>
|
||||
#include <type_traits>
|
||||
|
||||
template<typename T, auto Min, auto Max>
|
||||
template<std::movable T, UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Min,
|
||||
UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Max>
|
||||
inline constexpr auto is_in_range = [](const auto& v) { return std::clamp(v, T{Min}, T{Max}) == v; };
|
||||
|
||||
template<typename T, auto Min, auto Max>
|
||||
template<std::movable T, UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Min,
|
||||
UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Max>
|
||||
using is_in_range_t = decltype(is_in_range<T, Min, Max>);
|
||||
|
||||
template<typename T, auto Min, auto Max>
|
||||
template<std::movable T, UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Min,
|
||||
UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Max>
|
||||
class ranged_representation : public validated_type<T, is_in_range_t<T, Min, Max>> {
|
||||
public:
|
||||
using validated_type<T, is_in_range_t<T, Min, Max>>::validated_type;
|
||||
constexpr ranged_representation() : validated_type<T, is_in_range_t<T, Min, Max>>(T{}) {}
|
||||
|
||||
[[nodiscard]] constexpr ranged_representation operator-() const { return ranged_representation(-this->value()); }
|
||||
[[nodiscard]] constexpr ranged_representation operator-() const
|
||||
requires requires(T t) { -t; }
|
||||
{
|
||||
return ranged_representation(-this->value());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, auto Min, auto Max>
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
|
||||
constexpr explicit validated_type(const T& value) noexcept(std::is_nothrow_copy_constructible_v<T>)
|
||||
requires std::copyable<T>
|
||||
: value_(value)
|
||||
: value_(value)
|
||||
{
|
||||
gsl_Expects(validate(value_));
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
constexpr validated_type(const T& value, validated_tag) noexcept(std::is_nothrow_copy_constructible_v<T>)
|
||||
requires std::copyable<T>
|
||||
: value_(value)
|
||||
: value_(value)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -61,12 +61,30 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#if UNITS_COMP_MSVC && UNITS_COMP_MSVC < 1930
|
||||
|
||||
constexpr explicit(false) operator T() const noexcept(std::is_nothrow_copy_constructible_v<T>)
|
||||
requires std::copyable<T>
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
constexpr explicit(false) operator T() const& noexcept(std::is_nothrow_copy_constructible_v<T>)
|
||||
requires std::copyable<T>
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
constexpr explicit(false) operator T() && noexcept(std::is_nothrow_move_constructible_v<T>)
|
||||
{
|
||||
return std::move(value_);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
constexpr T& value() & noexcept = delete;
|
||||
constexpr const T& value() const& noexcept { return value_; }
|
||||
constexpr T&& value() && noexcept { return std::move(value_); }
|
||||
|
||||
Reference in New Issue
Block a user