forked from mpusz/mp-units
refactor: 💥 q_* UDL renamed to _q_*
We had some fun exploring the STD UDLs for potential collisions, we have learnt our lesson and know how to proceed. Now is high time to start behaving and obeying C++ rules.
This commit is contained in:
@@ -56,11 +56,11 @@ using namespace units::physical::si::literals;
|
||||
|
||||
int main()
|
||||
{
|
||||
auto box = Box{1000.0q_mm, 500.0q_mm, 200.0q_mm};
|
||||
box.set_contents_density(1000.0q_kg_per_m3);
|
||||
auto box = Box{1000.0_q_mm, 500.0_q_mm, 200.0_q_mm};
|
||||
box.set_contents_density(1000.0_q_kg_per_m3);
|
||||
|
||||
auto fill_time = 200.0q_s; // time since starting fill
|
||||
auto measured_mass = 20.0q_kg; // measured mass at fill_time
|
||||
auto fill_time = 200.0_q_s; // time since starting fill
|
||||
auto measured_mass = 20.0_q_kg; // measured mass at fill_time
|
||||
|
||||
std::cout << "mpusz/units box example ( using experimental alternative syntax for defining quantities) ...\n";
|
||||
std::cout << "fill height at " << fill_time << " = " << box.fill_level(measured_mass) << " ("
|
||||
|
||||
@@ -36,22 +36,22 @@ int main()
|
||||
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
|
||||
std::cout.precision(3);
|
||||
|
||||
constexpr auto C = 0.47q_uF;
|
||||
constexpr auto V0 = 5.0q_V;
|
||||
constexpr auto R = 4.7q_kR;
|
||||
constexpr auto C = 0.47_q_uF;
|
||||
constexpr auto V0 = 5.0_q_V;
|
||||
constexpr auto R = 4.7_q_kR;
|
||||
|
||||
for (auto t = 0q_ms; t <= 50q_ms; ++t) {
|
||||
for (auto t = 0_q_ms; t <= 50_q_ms; ++t) {
|
||||
const auto Vt = V0 * units::exp(-t / (R * C));
|
||||
|
||||
std::cout << "at " << t << " voltage is ";
|
||||
|
||||
if (Vt >= 1q_V)
|
||||
if (Vt >= 1_q_V)
|
||||
std::cout << Vt;
|
||||
else if (Vt >= 1q_mV)
|
||||
else if (Vt >= 1_q_mV)
|
||||
std::cout << voltage::mV<>{Vt};
|
||||
else if (Vt >= 1q_uV)
|
||||
else if (Vt >= 1_q_uV)
|
||||
std::cout << voltage::uV<>{Vt};
|
||||
else if (Vt >= 1q_nV)
|
||||
else if (Vt >= 1_q_nV)
|
||||
std::cout << voltage::nV<>{Vt};
|
||||
else
|
||||
std::cout << voltage::pV<>{Vt};
|
||||
|
||||
@@ -33,12 +33,12 @@ void simple_quantities()
|
||||
using distance = length::m<>;
|
||||
using q_time = q_time::s<>;
|
||||
|
||||
constexpr distance km = 1.0q_km;
|
||||
constexpr distance miles = 1.0q_mi;
|
||||
constexpr distance km = 1.0_q_km;
|
||||
constexpr distance miles = 1.0_q_mi;
|
||||
|
||||
constexpr q_time sec = 1q_s;
|
||||
constexpr q_time min = 1q_min;
|
||||
constexpr q_time hr = 1q_h;
|
||||
constexpr q_time sec = 1_q_s;
|
||||
constexpr q_time min = 1_q_min;
|
||||
constexpr q_time hr = 1_q_h;
|
||||
|
||||
std::cout << "A physical quantities library can choose the simple\n";
|
||||
std::cout << "option to provide output using a single type for each base unit:\n\n";
|
||||
@@ -51,12 +51,12 @@ void simple_quantities()
|
||||
|
||||
void quantities_with_typed_units()
|
||||
{
|
||||
constexpr length::km<> km = 1.0q_km;
|
||||
constexpr length::mi<> miles = 1.0q_mi;
|
||||
constexpr length::km<> km = 1.0_q_km;
|
||||
constexpr length::mi<> miles = 1.0_q_mi;
|
||||
|
||||
constexpr q_time::s<> sec = 1q_s;
|
||||
constexpr q_time::min<> min = 1q_min;
|
||||
constexpr q_time::h<> hr = 1q_h;
|
||||
constexpr q_time::s<> sec = 1_q_s;
|
||||
constexpr q_time::min<> min = 1_q_min;
|
||||
constexpr q_time::h<> hr = 1_q_h;
|
||||
|
||||
std::cout << "A more flexible option is to provide separate types for each unit,\n\n";
|
||||
std::cout << km << '\n';
|
||||
@@ -65,7 +65,7 @@ void quantities_with_typed_units()
|
||||
std::cout << min << '\n';
|
||||
std::cout << hr << "\n\n";
|
||||
|
||||
constexpr length::m<> meter = 1q_m;
|
||||
constexpr length::m<> meter = 1_q_m;
|
||||
std::cout << "then a wide range of pre-defined units can be defined and converted,\n"
|
||||
" for consistency and repeatability across applications:\n\n";
|
||||
|
||||
@@ -97,8 +97,8 @@ void calcs_comparison()
|
||||
"when adding two values of the same very big\n"
|
||||
"or very small type:\n\n";
|
||||
|
||||
length::fm<float> L1A = 2.q_fm;
|
||||
length::fm<float> L2A = 3.q_fm;
|
||||
length::fm<float> L1A = 2._q_fm;
|
||||
length::fm<float> L2A = 3._q_fm;
|
||||
length::fm<float> LrA = L1A + L2A;
|
||||
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n",L1A,L2A,LrA);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ int main()
|
||||
{
|
||||
std::cout << "conversion factor in mpusz/units...\n\n";
|
||||
|
||||
constexpr length::m<> lengthA = 2.0q_m;
|
||||
constexpr length::m<> lengthA = 2.0_q_m;
|
||||
constexpr length::mm<> lengthB = lengthA;
|
||||
|
||||
std::cout << "lengthA( " << lengthA << " ) and lengthB( " << lengthB << " )\n"
|
||||
|
||||
@@ -13,7 +13,7 @@ int main()
|
||||
{
|
||||
std::cout << "Simple timer using mpusz/units ...\n";
|
||||
|
||||
auto const period = 0.5q_s;
|
||||
auto const period = 0.5_q_s;
|
||||
auto const duration = 10 * period;
|
||||
|
||||
timer t;
|
||||
|
||||
Reference in New Issue
Block a user