refactor: quantity_spec::operator[] return type constraints improved

This commit is contained in:
Mateusz Pusz
2022-12-22 21:26:51 +01:00
parent 858cbb472f
commit 57d655062c

View File

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