The purpose of that workshop is to create a simple physical units library for C++.
It will support:
- several physical dimensions,
- automatic conversions between different units,
- compile time expressions verification,
- literals to easily work with different dimensions and their various units.
Above features will be provided without any runtime performance overhead.
Example:
static_assert(1000 / 1_s == 1_kHz);
static_assert(1_h == 3600_s);
static_assert(1_km + 1_m == 1001_m);
static_assert(10_km / 5_km == 2);
static_assert(10_km / 2 == 5_km);
static_assert(1_km / 1_s == 1000_mps);
static_assert(2_kmph * 2_h == 4_km);
static_assert(2_km / 2_kmph == 1_h);
- While solving workshop tasks please do not modify the code in the
ref
directory to not hit merge conflicts when moving to the next task. - The initial state of the task is always provided in the
ref/include
directory. If you want to use the reference implementation for the next tasks (instead using the one you wrote) than copy headers fromref/include
toinclude
before starting the assignment. - Reference unit tests and examples are always in
ref/src
directory. The target of each task is to make that code compile and pass without any issues. - If you want to add additional unit tests than please do so in
src/tests.cpp
file.
static_assert(10_m / 5_s == 2_mps);
static_assert(1_km / 1_s == 1000_mps);
static_assert(2_kmph * 2_h == 4_km);
static_assert(10_Hz * 10_s == 100);
static_assert(2_km / 2_kmph == 1_h);
-
Add definitions to
velocity.h
header (at leastmps
andkmph
). -
Add the following operator overloads to
quantity
interfacerep operator*(quantity, quantity)
quantity operator*(quantity, quantity)
quantity operator/(quantity, quantity)
for different dimensions
-
rep operator*(quantity, quantity)
should participate in the overload resolution only if the following are true:same_dim<typename Unit::dimension, dim_invert<typename Unit2::dimension>>
-
quantity operator*(quantity, quantity)
should participate in the overload resolution only if the following are true:!same_dim<typename Unit::dimension, dim_invert<typename Unit2::dimension>>
treat_as_floating_point<decltype(std::declval<Rep>() * std::declval<Rep2>())>
orstd::ratio_multiply<typename Unit::ratio, typename Unit2::ratio>::den == 1
-
quantity operator/(quantity, quantity)
should participate in the overload resolution only if the following are true:!same_dim<typename Unit::dimension, dim_invert<typename Unit2::dimension>>
treat_as_floating_point<decltype(std::declval<Rep>() / std::declval<Rep2>())>
orstd::ratio_divide<typename Unit::ratio, typename Unit2::ratio>::den == 1