Shamrock units library
This is the units library in use in the Shamrock code, this repository will be updated when change are made to this library in the Shamrock monorepo.
Almost everything is marked constexpr in the library, so most of the conversion if possible will be opmitized away by the compiler, allowing for zero cost abstraction here :)
Here is an example of the usage of the units library :
#include <iostream>
int main(void){
UnitSystem<double> si {};
std::cout << si.
get<units::astronomical_unit,2>() << std::endl;
UnitSystem<double> astro_units {
si.
get<mega, units::years>(),
si.
get<units::astronomical_unit>(),
si.
get<units::kilogram>()*sol_mass,
};
std::cout << astro_units.
get<units::astronomical_unit,2>() << std::endl;
std::cout << astro_cte.
G() << std::endl;
double value = 12;
std::cout <<
"value = "<< astro_units.
to<units::second>() <<
" s"<< std::endl;
}
constexpr T get() const noexcept
get the value of a units in the current system
constexpr T to()
To the si units (convert a system unit to si ones). This function is the inverse of get.
namespace containing the units library
constexpr T sol_mass()
get the value of a sol_mass in the mass unit of the current unit system units
constexpr T G()
get the value of G in the current unit system units
If you want to try here is a godbolt link : https://godbolt.org/z/5zjGMea57