mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 19:04:27 +02:00
refactor(example): RepresentationOf
support added to examples
This commit is contained in:
@@ -31,6 +31,10 @@
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units;
|
||||
@@ -57,7 +61,7 @@ public:
|
||||
return quantity_cast<isq::weight>(mass * g);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr quantity<isq::length[m]> fill_level(const quantity<isq::mass[kg]>& measured_mass) const
|
||||
[[nodiscard]] constexpr quantity<isq::height[m]> fill_level(const quantity<isq::mass[kg]>& measured_mass) const
|
||||
{
|
||||
return height_ * measured_mass * g / filled_weight();
|
||||
}
|
||||
|
@@ -117,11 +117,15 @@ private:
|
||||
|
||||
} // namespace
|
||||
|
||||
template<class T>
|
||||
inline constexpr bool units::is_scalar<measurement<T>> = true;
|
||||
template<class T>
|
||||
inline constexpr bool units::is_vector<measurement<T>> = true;
|
||||
|
||||
static_assert(units::RepresentationOf<measurement<double>, units::quantity_character::scalar>);
|
||||
|
||||
namespace {
|
||||
|
||||
static_assert(units::Representation<measurement<double>>);
|
||||
|
||||
void example()
|
||||
{
|
||||
using namespace units;
|
||||
@@ -130,7 +134,7 @@ void example()
|
||||
const auto a = measurement{9.8, 0.1} * isq::acceleration[m / s2];
|
||||
const auto t = measurement{1.2, 0.1} * isq::time[s];
|
||||
|
||||
const weak_quantity_of<isq::speed> auto v = a * t;
|
||||
const weak_quantity_of<isq::velocity> auto v = a * t;
|
||||
std::cout << a << " * " << t << " = " << v << " = " << v[km / h] << '\n';
|
||||
|
||||
const auto length = measurement{123., 1.} * isq::length[si::metre];
|
||||
|
@@ -25,6 +25,10 @@
|
||||
#include <units/si/unit_symbols.h>
|
||||
#include <iostream>
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units::si;
|
||||
|
@@ -34,6 +34,10 @@
|
||||
#include <limits>
|
||||
#include <locale>
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
|
||||
using namespace units;
|
||||
using namespace units::si::unit_symbols;
|
||||
|
||||
|
Reference in New Issue
Block a user