forked from mpusz/mp-units
refactor: UDLs support switched off by default
This commit is contained in:
@@ -39,43 +39,37 @@
|
||||
namespace {
|
||||
|
||||
using namespace units::isq;
|
||||
using namespace si::references;
|
||||
|
||||
using m = si::metre;
|
||||
using m2 = si::square_metre;
|
||||
using m3 = si::cubic_metre;
|
||||
using kg = si::kilogram;
|
||||
using N = si::newton;
|
||||
using kgpm3 = si::kilogram_per_metre_cub;
|
||||
|
||||
inline constexpr auto g = si::si2019::standard_gravity<>;
|
||||
inline constexpr si::density<kgpm3> air_density(1.225);
|
||||
inline constexpr Acceleration auto g = si::si2019::standard_gravity<>;
|
||||
inline constexpr Density auto air_density = 1.225 * (kg / m3);
|
||||
|
||||
|
||||
class Box {
|
||||
si::area<m2> base_;
|
||||
si::length<m> height_;
|
||||
si::density<kgpm3> density_ = air_density;
|
||||
si::area<si::square_metre> base_;
|
||||
si::length<si::metre> height_;
|
||||
si::density<si::kilogram_per_metre_cub> density_ = air_density;
|
||||
public:
|
||||
constexpr Box(const si::length<m>& length, const si::length<m>& width, si::length<m> height) : base_(length * width), height_(std::move(height)) {}
|
||||
constexpr Box(const si::length<si::metre>& length, const si::length<si::metre>& width, si::length<si::metre> height) : base_(length * width), height_(std::move(height)) {}
|
||||
|
||||
[[nodiscard]] constexpr si::force<N> filled_weight() const
|
||||
[[nodiscard]] constexpr si::force<si::newton> filled_weight() const
|
||||
{
|
||||
const si::volume<m3> volume = base_ * height_;
|
||||
const si::mass<kg> mass = density_ * volume;
|
||||
const Volume auto volume = base_ * height_;
|
||||
const Mass auto mass = density_ * volume;
|
||||
return mass * g;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr si::length<m> fill_level(const si::mass<kg>& measured_mass) const
|
||||
[[nodiscard]] constexpr si::length<si::metre> fill_level(const si::mass<si::kilogram>& measured_mass) const
|
||||
{
|
||||
return height_ * measured_mass * g / filled_weight();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr si::volume<m3> spare_capacity(const si::mass<kg>& measured_mass) const
|
||||
[[nodiscard]] constexpr si::volume<si::cubic_metre> spare_capacity(const si::mass<si::kilogram>& measured_mass) const
|
||||
{
|
||||
return (height_ - fill_level(measured_mass)) * base_;
|
||||
}
|
||||
|
||||
constexpr void set_contents_density(const si::density<kgpm3>& density_in)
|
||||
constexpr void set_contents_density(const si::density<si::kilogram_per_metre_cub>& density_in)
|
||||
{
|
||||
assert(density_in > air_density);
|
||||
density_ = density_in;
|
||||
@@ -88,14 +82,13 @@ public:
|
||||
int main()
|
||||
{
|
||||
using namespace units;
|
||||
using namespace si::literals;
|
||||
|
||||
const si::length<m> height(200.0_q_mm);
|
||||
auto box = Box(1000.0_q_mm, 500.0_q_mm, height);
|
||||
box.set_contents_density(1000.0_q_kg_per_m3);
|
||||
const si::length<si::metre> height = 200.0 * mm;
|
||||
auto box = Box(1000.0 * mm, 500.0 * mm, height);
|
||||
box.set_contents_density(1000.0 * (kg / m3));
|
||||
|
||||
const auto fill_time = 200.0_q_s; // time since starting fill
|
||||
const auto measured_mass = 20.0_q_kg; // measured mass at fill_time
|
||||
const auto fill_time = 200.0 * s; // time since starting fill
|
||||
const auto measured_mass = 20.0 * kg; // measured mass at fill_time
|
||||
|
||||
const Length auto fill_level = box.fill_level(measured_mass);
|
||||
const Dimensionless auto fill_percent = quantity_cast<percent>(fill_level / height);
|
||||
|
Reference in New Issue
Block a user