mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-02 11:54:27 +02:00
refactor: conversions part of the custom_systems
refactored to be more explicit
This commit is contained in:
@@ -65,11 +65,21 @@ using length = quantity<dim_length, U, Rep>;
|
|||||||
} // namespace fps
|
} // namespace fps
|
||||||
} // namespace si
|
} // namespace si
|
||||||
|
|
||||||
|
template<typename Q, typename U>
|
||||||
|
concept castable_to = Quantity<Q> && Unit<U> &&
|
||||||
|
requires (Q q) {
|
||||||
|
quantity_cast<U>(q);
|
||||||
|
};
|
||||||
|
|
||||||
void conversions()
|
void conversions()
|
||||||
{
|
{
|
||||||
// constexpr auto fps_yard = fps::length<fps::yard>(1.);
|
// fps::yard is not defined in terms of SI units (or vice-versa)
|
||||||
// std::cout << quantity_cast<si::kilometre>(fps_yard) << "\n";
|
// so the conversion between FPS and SI is not possible
|
||||||
|
static_assert(!castable_to<fps::length<fps::yard>, si::kilometre>);
|
||||||
|
|
||||||
|
// si::fps::yard is defined in terms of SI units
|
||||||
|
// so the conversion between FPS and SI is possible
|
||||||
|
static_assert(castable_to<si::fps::length<si::fps::yard>, si::kilometre>);
|
||||||
constexpr auto si_fps_yard = si::fps::length<si::fps::yard>(1.);
|
constexpr auto si_fps_yard = si::fps::length<si::fps::yard>(1.);
|
||||||
std::cout << quantity_cast<si::kilometre>(si_fps_yard) << "\n";
|
std::cout << quantity_cast<si::kilometre>(si_fps_yard) << "\n";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user