mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 02:17:16 +02:00
units building and packaging redesigned + Travis CI support
This commit is contained in:
@ -23,26 +23,40 @@
|
||||
#include "units/si/velocity.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace units;
|
||||
namespace {
|
||||
|
||||
template<Velocity V, Time T>
|
||||
void foo(V v, T t)
|
||||
using namespace units::literals;
|
||||
|
||||
template<units::Length D, units::Time T>
|
||||
constexpr units::Velocity avg_speed(D d, T t)
|
||||
{
|
||||
const Length distance = v * t;
|
||||
std::cout << "A car driving " << v.count() << " km/h in a time of " << t.count() << " minutes will pass "
|
||||
<< quantity_cast<length<meter, double>>(distance).count() << " meters.\n";
|
||||
return d / t;
|
||||
}
|
||||
|
||||
void foo()
|
||||
template<units::Velocity V, units::Time T>
|
||||
void example_1(V v, T t)
|
||||
{
|
||||
using namespace units::literals;
|
||||
foo(60_kmph, 10.0_min);
|
||||
const units::Length distance = v * t;
|
||||
std::cout << "A car driving " << v.count() << " km/h in a time of " << t.count() << " minutes will pass "
|
||||
<< units::quantity_cast<units::length<units::meter, double>>(distance).count() << " meters.\n";
|
||||
}
|
||||
|
||||
void example_2(double distance_v, double duration_v)
|
||||
{
|
||||
units::length<units::kilometer> distance(distance_v);
|
||||
units::time<units::hour> duration(duration_v);
|
||||
const auto kmph = avg_speed(distance, duration);
|
||||
std::cout << "Average speed of a car that makes " << distance.count() << " km in "
|
||||
<< duration.count() << " hours is " << kmph.count() << " km/h.\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
foo();
|
||||
example_1(60_kmph, 10.0_min);
|
||||
example_2(220, 2);
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
|
Reference in New Issue
Block a user