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_m
sipp::Kilometers
, literal_km
sipp::Millimeters
, literal_mm
sipp::Micrometers
, literal_um
sipp::Nanometers
, literal_nm
sipp::Feet
, literal_ft
sipp::NauticalMiles
, literal_NM
sipp::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_h
sipp::MetersPerSecond
, literal_m_s
sipp::FeetPerSecond
, literal_ft_s
sipp::FeetPerMinute
, literal_ft_min
sipp::Knots
, literal_kts
sipp::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