mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 21:54:28 +02:00
refactor: get_associated_quantity.h
moved to a dedicated header file
This commit is contained in:
@@ -43,6 +43,7 @@ add_library(
|
||||
include/mp_units/bits/algorithm.h
|
||||
include/mp_units/bits/dimension_concepts.h
|
||||
include/mp_units/bits/expression_template.h
|
||||
include/mp_units/bits/get_associated_quantity.h
|
||||
include/mp_units/bits/magnitude.h
|
||||
include/mp_units/bits/math_concepts.h
|
||||
include/mp_units/bits/prime.h
|
||||
|
54
src/core/include/mp_units/bits/get_associated_quantity.h
Normal file
54
src/core/include/mp_units/bits/get_associated_quantity.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2018 Mateusz Pusz
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mp_units/bits/expression_template.h>
|
||||
#include <mp_units/bits/unit_concepts.h>
|
||||
#include <mp_units/quantity_spec.h>
|
||||
|
||||
namespace mp_units::detail {
|
||||
|
||||
template<typename U, auto... Vs>
|
||||
[[nodiscard]] consteval auto get_associated_quantity(power<U, Vs...>)
|
||||
{
|
||||
return pow<Vs...>(get_associated_quantity(U{}));
|
||||
}
|
||||
|
||||
template<typename... Us>
|
||||
[[nodiscard]] consteval auto get_associated_quantity(type_list<Us...>)
|
||||
{
|
||||
return (dimensionless * ... * get_associated_quantity(Us{}));
|
||||
}
|
||||
|
||||
template<AssociatedUnit U>
|
||||
[[nodiscard]] consteval auto get_associated_quantity(U)
|
||||
{
|
||||
if constexpr (requires { U::reference_unit; })
|
||||
return get_associated_quantity(U::reference_unit);
|
||||
else if constexpr (requires { typename U::_num_; })
|
||||
return get_associated_quantity(typename U::_num_{}) / get_associated_quantity(typename U::_den_{});
|
||||
else if constexpr (requires { U::quantity_spec; })
|
||||
return U::quantity_spec;
|
||||
}
|
||||
|
||||
} // namespace mp_units::detail
|
@@ -22,43 +22,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mp_units/bits/get_associated_quantity.h>
|
||||
#include <mp_units/bits/quantity_concepts.h>
|
||||
#include <mp_units/bits/reference_concepts.h>
|
||||
#include <mp_units/bits/representation_concepts.h>
|
||||
#include <mp_units/quantity_spec.h>
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<AssociatedUnit U>
|
||||
[[nodiscard]] consteval auto get_associated_quantity(U);
|
||||
|
||||
template<typename U, auto... Vs>
|
||||
[[nodiscard]] consteval auto get_associated_quantity(power<U, Vs...>)
|
||||
{
|
||||
return get_associated_quantity(U{});
|
||||
}
|
||||
|
||||
template<typename... Us>
|
||||
[[nodiscard]] consteval auto get_associated_quantity(type_list<Us...>)
|
||||
{
|
||||
return (dimensionless * ... * get_associated_quantity(Us{}));
|
||||
}
|
||||
|
||||
template<AssociatedUnit U>
|
||||
[[nodiscard]] consteval auto get_associated_quantity(U)
|
||||
{
|
||||
if constexpr (requires { U::reference_unit; })
|
||||
return get_associated_quantity(U::reference_unit);
|
||||
else if constexpr (requires { typename U::_num_; })
|
||||
return get_associated_quantity(typename U::_num_{}) / get_associated_quantity(typename U::_den_{});
|
||||
else if constexpr (requires { U::base_quantity; })
|
||||
return U::base_quantity;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
[[nodiscard]] consteval QuantitySpec auto get_quantity_spec(AssociatedUnit auto u)
|
||||
{
|
||||
return detail::get_associated_quantity(u);
|
||||
@@ -78,7 +48,6 @@ template<auto Q, auto U>
|
||||
return U;
|
||||
}
|
||||
|
||||
|
||||
template<Reference auto R, RepresentationOf<get_quantity_spec(R).character> Rep>
|
||||
class quantity;
|
||||
|
||||
|
Reference in New Issue
Block a user