From a9db3ec3fca46d958c2d352e261e522b4221c689 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 29 Dec 2020 13:48:15 +0100 Subject: [PATCH] refactor: Documentation and explicitly deleted operators provided for `one_rep` --- src/include/units/one_rep.h | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/include/units/one_rep.h b/src/include/units/one_rep.h index c3e81752..18d19df3 100644 --- a/src/include/units/one_rep.h +++ b/src/include/units/one_rep.h @@ -28,7 +28,42 @@ namespace units { +/** + * @brief A representation type to be used for unit constants + * + * This representation type is intended to be used in the unit constants definition: + * + * @code{.cpp} + * namespace unit_constants { + * + * inline constexpr auto m = length{}; + * inline constexpr auto km = length{}; + * + * } + * @endcode + * + * Unit constants simplify quantity creation: + * + * @code{.cpp} + * using namespace units::physical::si::unit_constants; + * + * auto d = 123 * m; + * auto v = 70 * km / h; + * @endcode + * + * Also, it is allowed to define custom unit constants from existing ones: + * + * @code{.cpp} + * constexpr auto Nm = N * m; + * constexpr auto mph = mi / h; + * @endcode + * + * `km * 3` or `s / 4` syntax is not allowed for quantity creation. + */ struct one_rep { + [[nodiscard]] friend constexpr one_rep operator*(one_rep, one_rep) { return {}; } + [[nodiscard]] friend constexpr one_rep operator/(one_rep, one_rep) { return {}; } + template [[nodiscard]] friend constexpr Rep operator*(const Rep& lhs, one_rep) { @@ -40,6 +75,11 @@ struct one_rep { return lhs; } + template + [[nodiscard]] friend constexpr Rep operator*(one_rep, const Rep&) = delete; + template + [[nodiscard]] friend constexpr Rep operator/(one_rep, const Rep&) = delete; + template [[nodiscard]] constexpr operator Rep() const noexcept {