4 ms·
FTA: if constexpr(Addable<T>){ /.../ } else if constexpr(requires(T a, T b) { a + b; }){ /.../ } The compiler knows that Addable<T> is a concept at this p
by sriram_sun 6y ago
FTA:
if constexpr(Addable<T>){ /.../ }
else if constexpr(requires(T a, T b) { a + b; }){ /.../ }
The compiler knows that Addable<T> is a concept at this point right? Is the constexpr required?
- gpderetta 6y agoAddable<T> should evaluate to bool, so you can actually use it with a plain if. But a plain if requires both true and false branches to type check and if your T is not actually addable and you use operator+ in the true branch you will get a compilation error.
- sriram_sun 6y agoAah got it. Thank you!