From 9fbf17be06ca9562a8f75bb9a88b48ce6f8e682d Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 25 Mar 2020 22:06:07 +0100 Subject: [PATCH] Scalar concept extended Scalar concept extended with types that are not constructible from and integral type --- docs/reference/concepts.rst | 9 ++++++++- src/include/units/concepts.h | 29 ++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/docs/reference/concepts.rst b/docs/reference/concepts.rst index 2e18c4b9..adbe3999 100644 --- a/docs/reference/concepts.rst +++ b/docs/reference/concepts.rst @@ -70,4 +70,11 @@ Concepts .. concept:: template Scalar - A concept matching non-Quantity types. Satisfied by types that satisfy :expr:`(!Quantity) && (!WrappedQuantity) && std::regular`. + A concept matching non-Quantity types. Satisfied by types that match + :expr:`(!Quantity) && (!WrappedQuantity) && std::regular` and satisfy one of the + following: + + - if type :expr:`T` is constructible from ``std::int64_t`` (which is the type that stores + the elements of `ratio`), :expr:`T * T` and :expr:`T / T` must be valid, + - otherwise, :expr:`T * std::int64_t`, :expr:`std::int64_t * T`, and :expr:`T / std::int64_t` + must be valid. diff --git a/src/include/units/concepts.h b/src/include/units/concepts.h index 9365f6cf..9f1a917e 100644 --- a/src/include/units/concepts.h +++ b/src/include/units/concepts.h @@ -248,6 +248,29 @@ template concept WrappedQuantity = detail::is_wrapped_quantity; // Scalar + +namespace detail { + +template +concept constructible_from_integral = + // construction from an integral type + std::constructible_from && + // unit scaling + std::regular_invocable, T, T> && + std::regular_invocable, T, T>; + +template +concept not_constructible_from_integral = + // not construction from an integral type + (!std::constructible_from) && + + // scaling by the value from ratio + std::regular_invocable, T, std::int64_t> && + std::regular_invocable, std::int64_t, T>; // && + // std::regular_invocable, T, std::int64_t>; // TODO Uncomment when a bug in LA is fixed + +} // namesapce detail + /** * @brief A concept matching non-Quantity types. * @@ -258,10 +281,6 @@ concept Scalar = (!Quantity) && (!WrappedQuantity) && std::regular && - // construction from an integral type - std::constructible_from && - // unit scaling - std::regular_invocable, T, T> && - std::regular_invocable, T, T>; + (detail::constructible_from_integral || detail::not_constructible_from_integral); } // namespace units