As always, we start with the inclusion of all the needed header files. After that, for
the simplicity of this example, we
hack the character of quantities
to be able to express vector quantities with simple scalar types.
intmain(){usingnamespacemp_units::si;usingnamespacemp_units::si::unit_symbols;std::cout<<"The seven defining constants of the SI and the seven corresponding units they define:\n";std::cout<<MP_UNITS_STD_FMT::format("- hyperfine transition frequency of Cs: {} = {:%.0Q %q}\n",1.*si2019::hyperfine_structure_transition_frequency_of_cs,(1.*si2019::hyperfine_structure_transition_frequency_of_cs).in(Hz));std::cout<<MP_UNITS_STD_FMT::format("- speed of light in vacuum: {} = {:%.0Q %q}\n",1.*si2019::speed_of_light_in_vacuum,(1.*si2019::speed_of_light_in_vacuum).in(m/s));std::cout<<MP_UNITS_STD_FMT::format("- Planck constant: {} = {:%.8eQ %q}\n",1.*si2019::planck_constant,(1.*si2019::planck_constant).in(J*s));std::cout<<MP_UNITS_STD_FMT::format("- elementary charge: {} = {:%.9eQ %q}\n",1.*si2019::elementary_charge,(1.*si2019::elementary_charge).in(C));std::cout<<MP_UNITS_STD_FMT::format("- Boltzmann constant: {} = {:%.6eQ %q}\n",1.*si2019::boltzmann_constant,(1.*si2019::boltzmann_constant).in(J/K));std::cout<<MP_UNITS_STD_FMT::format("- Avogadro constant: {} = {:%.8eQ %q}\n",1.*si2019::avogadro_constant,(1.*si2019::avogadro_constant).in(1/mol));std::cout<<MP_UNITS_STD_FMT::format("- luminous efficacy: {} = {}\n",1.*si2019::luminous_efficacy,(1.*si2019::luminous_efficacy).in(lm/W));}
The main part of the example prints all of the SI-defining constants. While analyzing the output of
this program (provided below), we can easily notice that a direct printing of the quantity provides
just a value 1 with a proper constant symbol. This is the main power of the
Faster-than-lightspeed Constants feature.
Only after we explicitly convert the unit of a quantity to proper SI units we get an actual numeric
value of the constant.
The seven defining constants of the SI and the seven corresponding units they define:
- hyperfine transition frequency of Cs: 1 Δν_Cs = 9192631770 Hz
- speed of light in vacuum: 1 c = 299792458 m/s
- Planck constant: 1 h = 6.62607015e-34 J s
- elementary charge: 1 e = 1.602176634e-19 C
- Boltzmann constant: 1 k = 1.380649e-23 J/K
- Avogadro constant: 1 N_A = 6.02214076e+23 1/mol
- luminous efficacy: 1 K_cd = 683 lm/W