2019-12-17 10:48:54 +01:00
|
|
|
// The MIT License (MIT)
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Mateusz Pusz
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
|
|
|
|
2023-06-22 18:22:41 +02:00
|
|
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
// !!! Before you commit any changes to this file please make sure to check if it !!!
|
|
|
|
// !!! renders correctly in the documentation "Examples" section. !!!
|
|
|
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
2024-01-06 08:51:01 +01:00
|
|
|
#include <mp-units/compat_macros.h>
|
2024-06-10 22:04:41 +02:00
|
|
|
#include <mp-units/ext/format.h>
|
2024-07-16 17:36:00 +02:00
|
|
|
#ifdef MP_UNITS_IMPORT_STD
|
|
|
|
import std;
|
|
|
|
#else
|
2024-01-23 21:49:17 +01:00
|
|
|
#include <iomanip>
|
2024-01-06 08:51:00 +01:00
|
|
|
#include <iostream>
|
2024-07-16 17:36:00 +02:00
|
|
|
#endif
|
2024-01-06 08:51:00 +01:00
|
|
|
#ifdef MP_UNITS_MODULES
|
|
|
|
import mp_units;
|
|
|
|
#else
|
2024-04-25 16:30:52 +02:00
|
|
|
#include <mp-units/systems/international.h>
|
|
|
|
#include <mp-units/systems/isq.h>
|
|
|
|
#include <mp-units/systems/si.h>
|
2024-01-06 08:51:00 +01:00
|
|
|
#endif
|
2019-12-17 10:48:54 +01:00
|
|
|
|
2022-12-29 20:18:48 +01:00
|
|
|
using namespace mp_units;
|
2019-12-17 10:48:54 +01:00
|
|
|
|
2023-06-16 10:26:34 +03:00
|
|
|
constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<isq::length> auto d, QuantityOf<isq::time> auto t)
|
2022-11-30 18:36:16 +01:00
|
|
|
{
|
2023-02-14 12:58:54 +01:00
|
|
|
return d / t;
|
2022-11-30 18:36:16 +01:00
|
|
|
}
|
2019-12-17 10:48:54 +01:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2022-12-29 20:18:48 +01:00
|
|
|
using namespace mp_units::si::unit_symbols;
|
|
|
|
using namespace mp_units::international::unit_symbols;
|
2022-09-08 19:21:47 +02:00
|
|
|
|
2023-09-29 21:40:24 -06:00
|
|
|
constexpr quantity v1 = 110 * km / h;
|
2023-09-13 08:58:38 +02:00
|
|
|
constexpr quantity v2 = 70 * mph;
|
|
|
|
constexpr quantity v3 = avg_speed(220. * km, 2 * h);
|
|
|
|
constexpr quantity v4 = avg_speed(isq::distance(140. * mi), 2 * isq::duration[h]);
|
|
|
|
constexpr quantity v5 = v3.in(m / s);
|
|
|
|
constexpr quantity v6 = value_cast<m / s>(v4);
|
|
|
|
constexpr quantity v7 = value_cast<int>(v6);
|
2022-09-08 19:21:47 +02:00
|
|
|
|
2024-04-18 22:29:09 +01:00
|
|
|
std::cout << v1 << '\n'; // 110 km/h
|
|
|
|
std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h
|
|
|
|
std::cout << MP_UNITS_STD_FMT::format("{:*^10}\n", v3); // *110 km/h*
|
|
|
|
std::cout << MP_UNITS_STD_FMT::format("{:%N in %U of %D}\n", v4); // 70 in mi/h of LT⁻¹
|
|
|
|
std::cout << MP_UNITS_STD_FMT::format("{::N[.2f]}\n", v5); // 30.56 m/s
|
|
|
|
std::cout << MP_UNITS_STD_FMT::format("{::N[.2f]U[dn]}\n", v6); // 31.29 m⋅s⁻¹
|
|
|
|
std::cout << MP_UNITS_STD_FMT::format("{:%N}\n", v7); // 31
|
2019-12-17 10:48:54 +01:00
|
|
|
}
|