feat: quantity_spec support added
This commit is contained in:
1 parent
e0101f14d9
commit
92c70f1a4e
32 files changed
+1524
-827
No files matched your search
@@ -34,15 +34,14 @@
|
||||
namespace {
|
||||
|
||||
using namespace units;
|
||||
using namespace units::si;
|
||||
using namespace units::si::unit_symbols;
|
||||
|
||||
inline constexpr auto g = 1 * standard_gravity;
|
||||
inline constexpr auto g = 1 * si::standard_gravity;
|
||||
inline constexpr auto air_density = 1.225 * isq::mass_density[kg / m3];
|
||||
|
||||
class Box {
|
||||
quantity<isq::area[m2]> base_;
|
||||
quantity<isq::length[m]> height_;
|
||||
quantity<isq::height[m]> height_;
|
||||
quantity<isq::mass_density[kg / m3]> density_ = air_density;
|
||||
public:
|
||||
constexpr Box(const quantity<isq::length[m]>& length, const quantity<isq::length[m]>& width,
|
||||
@@ -51,11 +50,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto filled_weight() const
|
||||
[[nodiscard]] constexpr quantity_of<isq::weight> auto filled_weight() const
|
||||
{
|
||||
const weak_quantity_of<isq::volume> auto volume = base_ * height_;
|
||||
const quantity_of<isq::mass> auto mass = density_ * volume;
|
||||
return mass * g;
|
||||
const weak_quantity_of<isq::mass> auto mass = density_ * volume;
|
||||
return quantity_cast<isq::weight>(mass * g);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr quantity<isq::length[m]> fill_level(const quantity<isq::mass[kg]>& measured_mass) const
|
||||
@@ -80,7 +79,9 @@ public:
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto mm = isq::length[unit_symbols::mm]; // helper reference value
|
||||
using namespace units::si;
|
||||
|
||||
constexpr auto mm = isq::length[unit_symbols::mm]; // helper reference object
|
||||
|
||||
const auto height = (200.0 * mm)[metre];
|
||||
auto box = Box(1000.0 * mm, 500.0 * mm, height);
|
||||
|
||||
@@ -152,7 +152,7 @@ public:
|
||||
leg(const waypoint& b, const waypoint& e) noexcept : begin_(&b), end_(&e) {}
|
||||
constexpr const waypoint& begin() const { return *begin_; };
|
||||
constexpr const waypoint& end() const { return *end_; }
|
||||
constexpr const distance get_length() const { return length_; }
|
||||
constexpr distance get_length() const { return length_; }
|
||||
};
|
||||
using legs = std::vector<leg>;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
using namespace units;
|
||||
|
||||
constexpr quantity_of<isq::speed> auto avg_speed(quantity_of<isq::length> auto d, quantity_of<isq::time> auto t)
|
||||
constexpr quantity_of<isq::speed> auto avg_speed(quantity_of<isq::distance> auto d, quantity_of<isq::duration> auto t)
|
||||
{
|
||||
return quantity_cast<isq::speed>(d / t);
|
||||
}
|
||||
@@ -42,8 +42,8 @@ int main()
|
||||
|
||||
constexpr auto v1 = 110 * isq::speed[km / h];
|
||||
constexpr auto v2 = 70. * isq::speed[mph];
|
||||
constexpr auto v3 = avg_speed(220 * isq::length[km], 2 * isq::time[h]);
|
||||
constexpr auto v4 = avg_speed(quantity<isq::length[mi]>{140}, quantity<isq::time[h]>{2});
|
||||
constexpr auto v3 = avg_speed(220 * isq::distance[km], 2 * isq::duration[h]);
|
||||
constexpr auto v4 = avg_speed(quantity<isq::distance[mi]>{140}, quantity<isq::duration[h]>{2});
|
||||
constexpr auto v5 = quantity_cast<quantity<isq::speed[m / s]>>(v3);
|
||||
constexpr auto v6 = quantity_cast<m / s>(v4);
|
||||
constexpr auto v7 = quantity_cast<int>(v6);
|
||||
|
||||
Reference in new issue
Block a user