The covariant return type is just fine, thank you very much. However, if
I want to create something like:
struct Consumer {
virtual unique_ptr<Provider> use();
};
struct ConcreteConsumer {
unique_ptr<ConcreteProvider> use() override {...}
};
struct Provider {...};
struct ConcreteProvider : public Provider {...}
Cannot be done. I understand the reason, but it seems to me unintuitive
that covariance does not "port" when using any of the std::xxx_ptr
types.
Furthermore, a corresponding implementation for ConcreteConsumer would
have to look like this to type derived from Provider:
struct ConcreteConsumer {
unique_ptr<Provider> use() override { return unique_ptr<Provider>{make_unique<ConcreteProvider>();}
};
In essence, I think that std::is_convertible<xxx_ptr<Derived>, xxx_ptr<Base>>should succeed in the same way that std::is_convertible<Derived*, Base*> succeeds, and overriding a member function that returns xxx_ptr where the types are covariant should be allowed.
Are there technical limitations? Seems to me that no abstractions would
be broken.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 376 |
Nodes: | 16 (2 / 14) |
Uptime: | 93:40:07 |
Calls: | 8,047 |
Calls today: | 3 |
Files: | 13,045 |
Messages: | 5,835,449 |