refactor: quantity_spec::operator[] return type constrained with Reference concept

This commit is contained in:
Mateusz Pusz
2022-12-22 16:48:28 +01:00
parent a32eb712da
commit be58a6e03a

View File

@@ -233,7 +233,7 @@ struct derived_quantity_spec : detail::expr_fractions<derived_quantity_spec<>, Q
#ifdef __cpp_explicit_this_parameter #ifdef __cpp_explicit_this_parameter
template<typename Self, Unit U> template<typename Self, Unit U>
[[nodiscard]] consteval auto operator[](this const Self, U u) [[nodiscard]] consteval Reference auto operator[](this const Self, U u)
requires(dimension == detail::get_dimension_for(u)) requires(dimension == detail::get_dimension_for(u))
{ {
return reference<Self{}, u>{}; return reference<Self{}, u>{};
@@ -241,7 +241,7 @@ struct derived_quantity_spec : detail::expr_fractions<derived_quantity_spec<>, Q
#else #else
// TODO can we somehow return an explicit reference type here? // TODO can we somehow return an explicit reference type here?
template<Unit U> template<Unit U>
[[nodiscard]] consteval auto operator[](U u) const [[nodiscard]] consteval Reference auto operator[](U u) const
requires(dimension == detail::get_dimension_for(u)) requires(dimension == detail::get_dimension_for(u))
{ {
return reference<derived_quantity_spec{}, u>{}; return reference<derived_quantity_spec{}, u>{};
@@ -318,12 +318,12 @@ struct quantity_spec<Self, Dim, Args...> {
#ifdef __cpp_explicit_this_parameter #ifdef __cpp_explicit_this_parameter
template<typename Self, Unit U> template<typename Self, Unit U>
[[nodiscard]] consteval auto operator[](this const Self, U u) [[nodiscard]] consteval Reference auto operator[](this const Self, U u)
requires(dimension == detail::get_dimension_for(u)) requires(dimension == detail::get_dimension_for(u))
#else #else
template<Unit U> template<Unit U>
// TODO can we somehow return an explicit reference type here? // TODO can we somehow return an explicit reference type here?
[[nodiscard]] consteval auto operator[](U u) const [[nodiscard]] consteval Reference auto operator[](U u) const
requires(dimension == detail::get_dimension_for(u)) requires(dimension == detail::get_dimension_for(u))
#endif #endif
{ {
@@ -386,7 +386,7 @@ struct quantity_spec<Self, Q, Args...> : std::remove_const_t<decltype(Q)> {
#ifndef __cpp_explicit_this_parameter #ifndef __cpp_explicit_this_parameter
template<Unit U> template<Unit U>
// TODO can we somehow return an explicit reference type here? // TODO can we somehow return an explicit reference type here?
[[nodiscard]] consteval auto operator[](U u) const [[nodiscard]] consteval Reference auto operator[](U u) const
requires(this->dimension == detail::get_dimension_for(u)) requires(this->dimension == detail::get_dimension_for(u))
{ {
return reference<Self{}, u>{}; return reference<Self{}, u>{};