add Chapter17
This commit is contained in:
33
Chapter17/fsm/util/inc/units.hpp
Normal file
33
Chapter17/fsm/util/inc/units.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
namespace units
|
||||
{
|
||||
template<typename T, typename ST>
|
||||
class unit {
|
||||
private:
|
||||
T val_;
|
||||
public:
|
||||
explicit unit(T val) : val_(val){}
|
||||
[[nodiscard]] T get() const {return val_;}
|
||||
[[nodiscard]] T get_mili() const {return 1e3 * val_;}
|
||||
|
||||
constexpr T operator/(const unit& second) const{
|
||||
return val_ / second.get();
|
||||
}
|
||||
|
||||
constexpr unit operator*(const T& second) const{
|
||||
return unit(val_ * second);
|
||||
}
|
||||
|
||||
constexpr unit operator/(const T& second) const{
|
||||
return unit(val_ / second);
|
||||
}
|
||||
};
|
||||
|
||||
using voltage = unit<float, struct the_voltage>;
|
||||
using resistance = unit<float, struct the_resistance>;
|
||||
|
||||
voltage operator""_V(long double volts);
|
||||
|
||||
resistance operator""_Ohm(long double ohms);
|
||||
};
|
||||
Reference in New Issue
Block a user