mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 05:34:27 +02:00
refactor: quantity_spec::operator[]
made consteval
This commit is contained in:
@@ -233,14 +233,15 @@ 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]] constexpr auto operator[](this const Self, U u)
|
[[nodiscard]] consteval 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>{};
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
// TODO can we somehow return an explicit reference type here?
|
||||||
template<Unit U>
|
template<Unit U>
|
||||||
[[nodiscard]] constexpr auto operator[](U u) const
|
[[nodiscard]] consteval 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>{};
|
||||||
@@ -317,11 +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]] constexpr auto operator[](this const Self, U u)
|
[[nodiscard]] consteval 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>
|
||||||
[[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))
|
requires(dimension == detail::get_dimension_for(u))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@@ -383,7 +385,8 @@ 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>
|
||||||
[[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))
|
requires(this->dimension == detail::get_dimension_for(u))
|
||||||
{
|
{
|
||||||
return reference<Self{}, u>{};
|
return reference<Self{}, u>{};
|
||||||
|
Reference in New Issue
Block a user