
In message <c1umak$2ou$1@sea.gmane.org>, Vladimir Prus <ghost@cs.msu.su> writes
Something is still unclear. If the number of individual values a type can hold is the only criteria for "widening", then is T* -> shared_ptr<T*> conversion widening? After all, shared_ptr<T*> can hold all pointer values out there, plus it holds reference count, so the total number of values is greater.
The number of legal values is, in principle and in practice, smaller: T o; boost::shared_ptr<T> p(&o); boost::shared_ptr<T> q(new T); // OK However, there is more to conversions than just narrower vs wider (see below).
If that's widening conversion, then constructor of shared_ptr<T*> need not be explicit, but that would be really unsafe. You say windening conversion often loose information, and in this fact you can easily loose information that pointer is allocated on stack, or that it's "this" pointer.
Information loss is not the deciding criterion for whether a conversion is narrowing or widening :-) Another distinction that needs to be made is that not all conversions fit into the widening/narrowing model. Some conversions are better considered as reinterpreting or translating conversions (eg lexical_cast and reinterpret_cast). These are useful where some notion of subtyping is not applicable, eg between int and string, as opposed to where one is, eg between numeric types. Kevlin -- ____________________________________________________________ Kevlin Henney phone: +44 117 942 2990 mailto:kevlin@curbralan.com mobile: +44 7801 073 508 http://www.curbralan.com fax: +44 870 052 2289 Curbralan: Consultancy + Training + Development + Review ____________________________________________________________