mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 12:54:25 +02:00
[msvc][fix] compiler does not get that expression can be evalutated to a const. (caused by read of variable outside its lifetime)
This commit is contained in:
@@ -1338,25 +1338,25 @@ template<NamedQuantitySpec From, DerivedQuantitySpec To>
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<QuantitySpec From, QuantitySpec To>
|
template<QuantitySpec From, QuantitySpec To>
|
||||||
[[nodiscard]] consteval specs_convertible_result convertible_kinds(From from_kind, To to_kind)
|
[[nodiscard]] consteval specs_convertible_result convertible_kinds(From, To)
|
||||||
{
|
{
|
||||||
constexpr auto exploded_kind_result = [](specs_convertible_result res) {
|
constexpr auto exploded_kind_result = [](specs_convertible_result res) {
|
||||||
using enum specs_convertible_result;
|
using enum specs_convertible_result;
|
||||||
return res == no ? no : yes;
|
return res == no ? no : yes;
|
||||||
};
|
};
|
||||||
if constexpr ((NamedQuantitySpec<decltype(from_kind)> && NamedQuantitySpec<decltype(to_kind)>) ||
|
if constexpr ((NamedQuantitySpec<decltype(From{})> && NamedQuantitySpec<decltype(To{})>) ||
|
||||||
get_complexity(from_kind) == get_complexity(to_kind))
|
get_complexity(From{}) == get_complexity(To{}))
|
||||||
return convertible_impl(from_kind, to_kind);
|
return convertible_impl(From{}, To{});
|
||||||
else if constexpr (get_complexity(from_kind) > get_complexity(to_kind))
|
else if constexpr (get_complexity(From{}) > get_complexity(To{}))
|
||||||
return exploded_kind_result(
|
return exploded_kind_result(
|
||||||
convertible_impl(get_kind_tree_root(explode<get_complexity(to_kind)>(from_kind).quantity), to_kind));
|
convertible_impl(get_kind_tree_root(explode<get_complexity(To{})>(From{}).quantity), To{}));
|
||||||
else
|
else
|
||||||
return exploded_kind_result(
|
return exploded_kind_result(
|
||||||
convertible_impl(from_kind, get_kind_tree_root(explode<get_complexity(from_kind)>(to_kind).quantity)));
|
convertible_impl(From{}, get_kind_tree_root(explode<get_complexity(From{})>(To{}).quantity)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<NamedQuantitySpec From, NamedQuantitySpec To>
|
template<NamedQuantitySpec From, NamedQuantitySpec To>
|
||||||
[[nodiscard]] consteval specs_convertible_result convertible_named(From from, To to)
|
[[nodiscard]] consteval specs_convertible_result convertible_named(From, To)
|
||||||
{
|
{
|
||||||
using enum specs_convertible_result;
|
using enum specs_convertible_result;
|
||||||
|
|
||||||
@@ -1369,16 +1369,16 @@ template<NamedQuantitySpec From, NamedQuantitySpec To>
|
|||||||
return no;
|
return no;
|
||||||
else if constexpr (get_complexity(From{}) != get_complexity(To{})) {
|
else if constexpr (get_complexity(From{}) != get_complexity(To{})) {
|
||||||
if constexpr (get_complexity(From{}) > get_complexity(To{}))
|
if constexpr (get_complexity(From{}) > get_complexity(To{}))
|
||||||
return convertible_impl(explode<get_complexity(to)>(from).quantity, to);
|
return convertible_impl(explode<get_complexity(To{})>(From{}).quantity, To{});
|
||||||
else {
|
else {
|
||||||
auto res = explode<get_complexity(from)>(to);
|
auto res = explode<get_complexity(From{})>(To{});
|
||||||
return min(res.result, convertible_impl(from, res.quantity));
|
return min(res.result, convertible_impl(From{}, res.quantity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<QuantitySpec From, QuantitySpec To>
|
template<QuantitySpec From, QuantitySpec To>
|
||||||
[[nodiscard]] consteval specs_convertible_result convertible_impl(From from, To to)
|
[[nodiscard]] consteval specs_convertible_result convertible_impl(From, To)
|
||||||
{
|
{
|
||||||
using enum specs_convertible_result;
|
using enum specs_convertible_result;
|
||||||
|
|
||||||
@@ -1388,30 +1388,30 @@ template<QuantitySpec From, QuantitySpec To>
|
|||||||
else if constexpr (From::dimension != To::dimension)
|
else if constexpr (From::dimension != To::dimension)
|
||||||
return no;
|
return no;
|
||||||
else if constexpr (QuantityKindSpec<From> || QuantityKindSpec<To>)
|
else if constexpr (QuantityKindSpec<From> || QuantityKindSpec<To>)
|
||||||
return convertible_kinds(get_kind_tree_root(from), get_kind_tree_root(to));
|
return convertible_kinds(get_kind_tree_root(From{}), get_kind_tree_root(To{}));
|
||||||
else if constexpr (NestedQuantityKindSpecOf<get_kind_tree_root(To{}), from> && get_kind_tree_root(To{}) == To{})
|
else if constexpr (NestedQuantityKindSpecOf<get_kind_tree_root(To{}), From{}> && get_kind_tree_root(To{}) == To{})
|
||||||
return yes;
|
return yes;
|
||||||
else if constexpr (NamedQuantitySpec<From> && NamedQuantitySpec<To>)
|
else if constexpr (NamedQuantitySpec<From> && NamedQuantitySpec<To>) {
|
||||||
return convertible_named(from, to);
|
return convertible_named(From{}, To{});
|
||||||
else if constexpr (DerivedQuantitySpec<From> && DerivedQuantitySpec<To>)
|
} else if constexpr (DerivedQuantitySpec<From> && DerivedQuantitySpec<To>) {
|
||||||
return are_ingredients_convertible(from, to);
|
return are_ingredients_convertible(From{}, To{});
|
||||||
else if constexpr (DerivedQuantitySpec<From>) {
|
} else if constexpr (DerivedQuantitySpec<From>) {
|
||||||
auto res = explode<get_complexity(to)>(from);
|
auto res = explode<get_complexity(To{})>(From{});
|
||||||
if constexpr (NamedQuantitySpec<decltype(res.quantity)>)
|
if constexpr (NamedQuantitySpec<decltype(res.quantity)>)
|
||||||
return convertible_impl(res.quantity, to);
|
return convertible_impl(res.quantity, To{});
|
||||||
else if constexpr (requires { to._equation_; }) {
|
else if constexpr (requires { To{}._equation_; }) {
|
||||||
auto eq = explode_to_equation(to);
|
auto eq = explode_to_equation(To{});
|
||||||
return min(eq.result, convertible_impl(res.quantity, eq.equation));
|
return min(eq.result, convertible_impl(res.quantity, eq.equation));
|
||||||
} else
|
} else
|
||||||
return are_ingredients_convertible(from, to);
|
return are_ingredients_convertible(From{}, To{});
|
||||||
} else if constexpr (DerivedQuantitySpec<To>) {
|
} else if constexpr (DerivedQuantitySpec<To>) {
|
||||||
auto res = explode<get_complexity(from)>(to);
|
auto res = explode<get_complexity(From{})>(To{});
|
||||||
if constexpr (NamedQuantitySpec<decltype(res.quantity)>)
|
if constexpr (NamedQuantitySpec<decltype(res.quantity)>)
|
||||||
return min(res.result, convertible_impl(from, res.quantity));
|
return min(res.result, convertible_impl(From{}, res.quantity));
|
||||||
else if constexpr (requires { from._equation_; })
|
else if constexpr (requires { From{}._equation_; })
|
||||||
return min(res.result, convertible_impl(from._equation_, res.quantity));
|
return min(res.result, convertible_impl(From{}._equation_, res.quantity));
|
||||||
else
|
else
|
||||||
return min(res.result, are_ingredients_convertible(from, to));
|
return min(res.result, are_ingredients_convertible(From{}, To{}));
|
||||||
}
|
}
|
||||||
// NOLINTEND(bugprone-branch-clone)
|
// NOLINTEND(bugprone-branch-clone)
|
||||||
return no;
|
return no;
|
||||||
@@ -1496,9 +1496,9 @@ template<QuantitySpec Q>
|
|||||||
MP_UNITS_EXPORT_BEGIN
|
MP_UNITS_EXPORT_BEGIN
|
||||||
|
|
||||||
template<QuantitySpec Q>
|
template<QuantitySpec Q>
|
||||||
[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q q)
|
[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q)
|
||||||
{
|
{
|
||||||
return kind_of<detail::get_kind_tree_root(q)>;
|
return kind_of<detail::get_kind_tree_root(Q{})>;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q) { return q; }
|
[[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q) { return q; }
|
||||||
|
Reference in New Issue
Block a user