Return type polymorphism and inheritance doesn't mix very well.
Swift got into this mess early in it's lifecycle and it's type checking is still more expensive than the rest of the compiler combined, and unpredictable on top of that.
Swift got into this mess early in it's lifecycle and it's type checking is still more expensive than the rest of the compiler combined, and unpredictable on top of that.
template<typename T>
T my_construct() { T result; return result; }edit: you get pseudo call-by-name as a bonus.
struct PolyReturn {
const int value;
operator int() const { return value; }
operator bool() const { return value > 0; }
};
https://cppinsights.io/s/f0b9976f