{ edited to shorten lines to ~70 characters (except code). -mod }
Consider:
struct Consumer {
virtual Provider* use();
};
struct ConcreteConsumer {
ConcreteProvider* use() override {...}
};
struct Provider {...};
struct ConcreteProvider : public Provider {...}
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.
Regards,
--Javier
--
[ See
http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)