I\'d like to write function interfaces that force the user to acknowledge the semantic meaning of built-in constants. For example, I\'d like to take
void rotate(
The key to this constraint is to declare your constructor explicit:
class Radians { public: explicit Radians(float value) : m_value(value) {} private: float m_value; };
That way your user can't type rotate(4.5). They'll have to type rotate(Radians(4.5)).
rotate(4.5)
rotate(Radians(4.5))