Welcome to C! Tiny suggestion to add to other comments: value
is already Boolean, so there's no need to write if (value == 1)
, you can just write if (value)
. Similarly, following @chamaeleon@kbin.social's suggestion of using the ternary operator, you can write return value ? "Yes" : "No";
.
That's a fair criticism around relying on implicit type conversion mechanics, and part of the tradeoff to make. On the other hand, I imagine (and my imagination may be limited) that one downside of
static_assert
is to increase verbosity, something like:auto r = f(); static_assert(std::is_same_v<decltype(r),MyReturnType>> || !is_expensive_conversion_v<MyReturnType>); return r;