|
|
|
|
|
by lionkor
1617 days ago
|
|
`bool metric` implies that `metric` can be YES or NO, that's clearer than what was there before. Its a made-up example, this discussion is about style, not about semantics. To please those who would like to see a semantically improved version: (C++) enum class Unit {
Meter,
Inch,
Foot,
// ...
};
template<Unit U>
struct UnitValue {
double value;
};
template<Unit U>
UnitValue<U> rectangle_area(UnitValue<U> side_a, UnitValue<U> side_b);
// invocation example
constexpr Unit unit = Unit::Meter;
UnitValue<unit> result = rectangle_area<unit>({5.3}, {1.5});
std::cout << result.value << std::endl;
There is still room for improvement, maybe some concepts to further generify it, some more comments, maybe a PDF with full documentation, ... |
|