diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index 632ff81c..83d13f67 100644 --- a/src/core/include/mp-units/quantity_spec.h +++ b/src/core/include/mp-units/quantity_spec.h @@ -104,7 +104,10 @@ struct quantity_spec_interface { template U> [[nodiscard]] consteval Reference auto operator[](this Self self, U u) { - return reference{}; + if constexpr (detail::QuantityKindSpec) + return u; + else + return reference{}; } template @@ -118,7 +121,10 @@ struct quantity_spec_interface { template U> [[nodiscard]] consteval Reference auto operator[](U u) const { - return reference{}; + if constexpr (detail::QuantityKindSpec) + return u; + else + return reference{}; } template @@ -294,7 +300,10 @@ struct quantity_spec : std::remove_const_t { template U> [[nodiscard]] consteval Reference auto operator[](U u) const { - return reference{}; + if constexpr (detail::QuantityKindSpec) + return u; + else + return reference{}; } template diff --git a/test/unit_test/static/reference_test.cpp b/test/unit_test/static/reference_test.cpp index 83e2cc60..7ab7de56 100644 --- a/test/unit_test/static/reference_test.cpp +++ b/test/unit_test/static/reference_test.cpp @@ -105,6 +105,13 @@ inline constexpr struct kilometre_ : decltype(si::kilo) {} kilometre; inline constexpr struct bit_ : named_unit<"bit", one, kind_of> {} bit; // clang-format on + +static_assert(is_of_type>); +static_assert(is_of_type[metre], metre_>); + +static_assert(is_of_type<(length / time)[metre / second], reference>); +static_assert(is_of_type<(kind_of / kind_of