mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 20:54:28 +02:00
Printing order of base units according to the recipe fixed
This commit is contained in:
@@ -104,20 +104,33 @@ constexpr auto derived_dimension_unit_text(exp_list<Es...> list)
|
||||
return derived_dimension_unit_text(list, std::index_sequence_for<Es...>());
|
||||
}
|
||||
|
||||
template<typename... Es>
|
||||
constexpr bool all_named(exp_list<Es...>)
|
||||
template<Exponent... Es>
|
||||
constexpr auto exp_list_with_named_units(exp_list<Es...>);
|
||||
|
||||
template<Exponent Exp>
|
||||
constexpr auto exp_list_with_named_units(Exp)
|
||||
{
|
||||
return (dimension_unit<typename Es::dimension>::is_named && ...);
|
||||
using dim = Exp::dimension;
|
||||
if constexpr(dimension_unit<dim>::is_named) {
|
||||
return exp_list<Exp>();
|
||||
}
|
||||
else {
|
||||
using recipe = dim::recipe;
|
||||
return exp_list_with_named_units(recipe());
|
||||
}
|
||||
}
|
||||
|
||||
template<Exponent... Es>
|
||||
constexpr auto exp_list_with_named_units(exp_list<Es...>)
|
||||
{
|
||||
return type_list_join<decltype(exp_list_with_named_units(Es()))...>();
|
||||
}
|
||||
|
||||
template<Dimension Dim>
|
||||
constexpr auto derived_dimension_unit_text()
|
||||
{
|
||||
using recipe = typename Dim::recipe;
|
||||
if constexpr(all_named(recipe()))
|
||||
return derived_dimension_unit_text(recipe());
|
||||
else
|
||||
return derived_dimension_unit_text(typename Dim::exponents());
|
||||
using recipe = Dim::recipe;
|
||||
return derived_dimension_unit_text(exp_list_with_named_units(recipe()));
|
||||
}
|
||||
|
||||
// TODO Inline below concept when switched to gcc-10
|
||||
|
@@ -21,7 +21,9 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "units/physical/si/area.h"
|
||||
#include "units/physical/si/constants.h"
|
||||
#include "units/physical/si/frequency.h"
|
||||
#include "units/physical/si/momentum.h"
|
||||
#include "units/physical/si/power.h"
|
||||
#include "units/physical/si/velocity.h"
|
||||
#include "units/physical/si/volume.h"
|
||||
@@ -150,6 +152,11 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
|
||||
CHECK(fmt::format("{}", 1q_mps2) == "1 m/s²");
|
||||
}
|
||||
|
||||
SECTION("momentum")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1q_kgmps) == "1 kg⋅m/s");
|
||||
}
|
||||
|
||||
SECTION("energy")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1q_mJ) == "1 mJ");
|
||||
|
Reference in New Issue
Block a user