On 24/04/2013 14:26, Daniel Kr?gler wrote:
On 2013-04-23 06:33, Balog Pal wrote:
The same is true for auto_ptr<foo *> and auto_ptr<const foo *> (and
many other flavors), yet they are implicitly convertible.
Just to get this right: We are talking about conversions here, not
about reinterpretations, right? (These are what the Standard smart
pointers support) If so, I don't understand the concern here, because
it is really not so hard to convert std::vector<foo *> to
std::vector<const foo *> via the iterator-pair constructor, which
supports all implicit conversions, so we can already write
std::vector<foo *> vf = ..;
std::vector<const foo *> vcf(vf.begin(), vf.end());
OK, I am probably losing it, but that creates a copy of vf. Worse than
that the copy has duplicated the pointers and so has the potential for
doing some real damage (remember that destruction is not a mutating
operation, at least it wasn't last time I looked)
The original problem concerned passing by reference which is not a
conversion but an attempt to add an extra constraint (that the pointers
may not be used to mutate the object)
looks comparable to me.
[ comp.lang.c++.moderated. First time posters: Do this! ]