From a32eb712da3f272e7cf63e1b071645e80c3d19cc Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 22 Dec 2022 15:58:37 +0100 Subject: [PATCH] refactor: `quantity_spec::operator[]` made `consteval` --- src/core/include/units/quantity_spec.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/include/units/quantity_spec.h b/src/core/include/units/quantity_spec.h index 7ceda6de..626f7c3d 100644 --- a/src/core/include/units/quantity_spec.h +++ b/src/core/include/units/quantity_spec.h @@ -233,14 +233,15 @@ struct derived_quantity_spec : detail::expr_fractions, Q #ifdef __cpp_explicit_this_parameter template - [[nodiscard]] constexpr auto operator[](this const Self, U u) + [[nodiscard]] consteval auto operator[](this const Self, U u) requires(dimension == detail::get_dimension_for(u)) { return reference{}; } #else + // TODO can we somehow return an explicit reference type here? template - [[nodiscard]] constexpr auto operator[](U u) const + [[nodiscard]] consteval auto operator[](U u) const requires(dimension == detail::get_dimension_for(u)) { return reference{}; @@ -317,11 +318,12 @@ struct quantity_spec { #ifdef __cpp_explicit_this_parameter template - [[nodiscard]] constexpr auto operator[](this const Self, U u) + [[nodiscard]] consteval auto operator[](this const Self, U u) requires(dimension == detail::get_dimension_for(u)) #else template - [[nodiscard]] constexpr auto operator[](U u) const + // TODO can we somehow return an explicit reference type here? + [[nodiscard]] consteval auto operator[](U u) const requires(dimension == detail::get_dimension_for(u)) #endif { @@ -383,7 +385,8 @@ struct quantity_spec : std::remove_const_t { #ifndef __cpp_explicit_this_parameter template - [[nodiscard]] constexpr auto operator[](U u) const + // TODO can we somehow return an explicit reference type here? + [[nodiscard]] consteval auto operator[](U u) const requires(this->dimension == detail::get_dimension_for(u)) { return reference{};