saturating_add vs. saturating_int – new function vs. new type?
Suppose you want to do integer arithmetic that saturates instead of overflowing.
The built-in operator+ doesn’t behave that way, so you need to roll something yourself.
Do you write a saturating_add() function or a new saturating_int type with overloaded operator+?
What about atomic_load(x) vs. atomic<int> x?
Or volatile_store(ptr, value) vs. volatile int*?
When should you provide functions that implement new behavior and when should you write a wrapper type? Let’s look at the pro and cons.
» read more »