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