bernedom / SI

A header only C++ library that provides type safety and user defined literals for physical units
https://si.dominikberner.ch/doc/
MIT License
488 stars 40 forks source link

A more intiutive way to define CONSTANTS of derived unit types #42

Closed bladan closed 4 years ago

bladan commented 4 years ago

Defining constants of derived data types could be more intiutive, as we have to always give a number before a literal: auto SPEED_CONSTANT = 10_km / 1_h;

How about allowing the line below or similar: auto SPEED_CONSTANT = 10_km/h;

bernedom commented 4 years ago

Would love to do that, but the C++ user defined literals do not allow for a / in the literal as it is a reserved character.

However in that case I would use something like this:

template <typename _type> using km_per_hour_t = velocity_t<_type, std::ratio<1000/3600>>;  
constexpr km_per_hour<double> SPEED_CONSTANT{10.0}; 

I'm considereing adding km_per_h_t and similar often used unit-types in a future release.

bladan commented 4 years ago

Something like km_per_h_t would be a good solution.