Skip to content
/ Units Public

physical unit type system made for modern C++ template metaprogramming learning

Notifications You must be signed in to change notification settings

Mapet13/Units

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

Units

Physical unit type system made created for modern C++ template metaprogramming learning

Goal

Main goal was to create type system where you can easly compare unit types. Unfortunetly I didn't achive that 100% becouse after many operations resulted type may have different order of arguments. But it actualy has the simplest form so I've partialy succesed.

Examples

// literals and math operation example
const auto time{ 10.0_s };
const auto distance{ 120.0_m };
const auto velocity{ distance / time };
const auto acceleration{ velocity / time };
const auto velocity_2{ acceleration * time };

// comparing types
static_assert(Is_same<decltype(time * distance), decltype(distance * time)>::value);
static_assert(!Is_same<decltype(time * distance), decltype(distance / time)>::value);

// example of physical constant made with units
template <std::floating_point T>
inline static constexpr units::Acceleration<T> gravitational_acceleration{ static_cast<T>(9.80665) };

About

physical unit type system made for modern C++ template metaprogramming learning

Topics

Resources

Stars

Watchers

Forks

Languages