Inspired by std::chrono, header-only library providing compile-time conversions and type-safety between different unit metrics.
Name SI comes from International System of Units, though the library now includes other unites as well.
Library provides 2 basic template types: Distance and Speed.
Think about these as std::chrono::duration<> template.
There are typedefs instantiating exact metric units (see below).
GCC 5+
or
Clang 3.8+
or
MS Visual Studio 2017+
#include <sipp/sipp.hpp>
// use <sipp/sipp_fwd.hpp> for just forward declarations
// ...
using namespace sipp::literals;
auto distance_in_km = 100.0_km;
sipp::Feet distance_in_feet = distance_in_km;
std::cout << "Distance in kilometers: " << distance_in_km.count() << std::endl;
std::cout << "Distance in feet: " << distance_in_feet.count() << std::endl;
auto casted = sipp::distance_cast<sipp::Meters>(5 * distance_in_km);
std::cout << "Multiplied kilometers and cast to meters: " << casted.count() << std::endl;
sipp::Meters, literal_msipp::Kilometers, literal_kmsipp::Millimeters, literal_mmsipp::Micrometers, literal_umsipp::Nanometers, literal_nmsipp::Feet, literal_ftsipp::NauticalMiles, literal_NMsipp::StatuteMiles, literal_mi
#include <sipp/sipp.hpp>
// ...
using namespace sipp::literals;
auto speed_in_kmh = 100.0_km_h;
sipp::Knots speed_in_knots = speed_in_kmh;
std::cout << "Speed in km/h " << speed_in_kmh.count() << std::endl;
std::cout << "Speed in knots: " << speed_in_knots.count() << std::endl;
auto casted = sipp::speed_cast<sipp::FeetPerMinute>(speed_in_knots + 10_m_s);
std::cout << "100 km/h + 10 m/s casted to feet/min: " << casted.count() << std::endl;
sipp::KmPerHour, literal_km_hsipp::MetersPerSecond, literal_m_ssipp::FeetPerSecond, literal_ft_ssipp::FeetPerMinute, literal_ft_minsipp::Knots, literal_ktssipp::MilesPerHour, literal_mph
There are unit tests, which can be built with cmake.
Requires googletest (which is in git submodule 3rdparty/googletest).
$ cd /path/to/sources
$ git submodule update --init --recursive
$ mkdir -p build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug ../
$ make sipp_tests
$ ./sipp_tests