mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 03:14:29 +02:00
refactor: total energy refactored to use CTAD instead of auto
This commit is contained in:
@@ -50,13 +50,13 @@ QuantityOf<isq::mechanical_energy> auto total_energy(QuantityOf<isq::momentum> a
|
||||
void si_example()
|
||||
{
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
constexpr auto GeV = si::giga<si::electronvolt>;
|
||||
constexpr QuantityOf<isq::speed> auto c = 1. * si::si2019::speed_of_light_in_vacuum;
|
||||
auto c2 = pow<2>(c);
|
||||
constexpr Unit auto GeV = si::giga<si::electronvolt>;
|
||||
constexpr quantity c = 1. * si::si2019::speed_of_light_in_vacuum;
|
||||
quantity c2 = pow<2>(c);
|
||||
|
||||
const auto p1 = isq::momentum(4. * GeV / c);
|
||||
const quantity p1 = isq::momentum(4. * GeV / c);
|
||||
const QuantityOf<isq::mass> auto m1 = 3. * GeV / c2;
|
||||
const auto E = total_energy(p1, m1, c);
|
||||
const quantity E = total_energy(p1, m1, c);
|
||||
|
||||
std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n";
|
||||
|
||||
@@ -65,18 +65,18 @@ void si_example()
|
||||
<< "m = " << m1 << "\n"
|
||||
<< "E = " << E << "\n";
|
||||
|
||||
const auto p2 = p1.in(GeV / (m / s));
|
||||
const auto m2 = m1.in(GeV / pow<2>(m / s));
|
||||
const auto E2 = total_energy(p2, m2, c).in(GeV);
|
||||
const quantity p2 = p1.in(GeV / (m / s));
|
||||
const quantity m2 = m1.in(GeV / pow<2>(m / s));
|
||||
const quantity E2 = total_energy(p2, m2, c).in(GeV);
|
||||
|
||||
std::cout << "\n[in `GeV`]\n"
|
||||
<< "p = " << p2 << "\n"
|
||||
<< "m = " << m2 << "\n"
|
||||
<< "E = " << E2 << "\n";
|
||||
|
||||
const auto p3 = p1.in(kg * m / s);
|
||||
const auto m3 = m1.in(kg);
|
||||
const auto E3 = total_energy(p3, m3, c).in(J);
|
||||
const quantity p3 = p1.in(kg * m / s);
|
||||
const quantity m3 = m1.in(kg);
|
||||
const quantity E3 = total_energy(p3, m3, c).in(J);
|
||||
|
||||
std::cout << "\n[in SI base units]\n"
|
||||
<< "p = " << p3 << "\n"
|
||||
@@ -92,10 +92,10 @@ void natural_example()
|
||||
using namespace mp_units::natural;
|
||||
using namespace mp_units::natural::unit_symbols;
|
||||
|
||||
constexpr auto c = 1. * speed_of_light;
|
||||
const auto p = 4. * momentum[GeV];
|
||||
const auto m = 3. * mass[GeV];
|
||||
const auto E = total_energy(p, m, c);
|
||||
constexpr quantity c = 1. * speed_of_light;
|
||||
const quantity p = 4. * momentum[GeV];
|
||||
const quantity m = 3. * mass[GeV];
|
||||
const quantity E = total_energy(p, m, c);
|
||||
|
||||
std::cout << "\n*** Natural units (c = " << c << ") ***\n"
|
||||
<< "p = " << p << "\n"
|
||||
|
Reference in New Issue
Block a user