From 554323d3a63b75c8809692842542a3ceba112ac6 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 16 Apr 2021 14:41:05 +0200 Subject: [PATCH] refactor: conversions part of the `custom_systems` refactored to be more explicit --- example/custom_systems.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/example/custom_systems.cpp b/example/custom_systems.cpp index f8fa8a3b..f3264aed 100644 --- a/example/custom_systems.cpp +++ b/example/custom_systems.cpp @@ -65,11 +65,21 @@ using length = quantity; } // namespace fps } // namespace si +template +concept castable_to = Quantity && Unit && + requires (Q q) { + quantity_cast(q); + }; + void conversions() { - // constexpr auto fps_yard = fps::length(1.); - // std::cout << quantity_cast(fps_yard) << "\n"; + // fps::yard is not defined in terms of SI units (or vice-versa) + // so the conversion between FPS and SI is not possible + static_assert(!castable_to, 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::kilometre>); constexpr auto si_fps_yard = si::fps::length(1.); std::cout << quantity_cast(si_fps_yard) << "\n"; }