Subject: [boost] Extrinsec conversions (Was [safebool] Can we generalize it and put it intoutilities?)
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-04-01 01:32:37
----- Original Message -----
From: "Eugene Wee" <crystalrecursion_at_[hidden]>
Sent: Wednesday, April 01, 2009 4:10 AM
Subject: Re: [boost] [safebool] Can we generalize it and put it intoutilities?
> On Wed, Apr 1, 2009 at 6:20 AM, Vladimir Batov
>> I glanced over "explicit conversion operators" in C++0x. It did not struck
>> me as
>> relevant to safe_bool. Care to elaborate?
> It is relevant since you can say, define an explicit conversion function to
> convert to bool, and yet avoid the very problems with say, also allowing
> implicit conversion to int, that the safe bool idiom is used to avoid. In
> other words, it is a language feature directly designed to replace the safe
> bool idiom, and more.
Thanks for the clarification.
Even if the following is not related to the safe bool idiom it is related to conversions.
The current standard allows to define intrinsec coversions, i.e. conversions that are defined either as a conversion operator on the from class or as a constructor on the to class.
Vladimir StringConvert proposal seems to go towards a conversion from/to strings (If I've understood?).
lexical_cast can be seen as an extrinsec converions of unrelated types via a common type stream type.
I have proposed a generic convert_to template function that generalize extrinsicaly the explicit convertion of unrelated types.
template <typename To, typename From> To convert_to(From&);
One difference is that for C++0x explicit conversion you can write
While for unrelated types you are forced to write
The other difference is that constructors and conversion operators can be implicit, while the convert_to function can not.
Do you think that it could be an interest in extending the C++0X standard to take care of these extrinsically defined conversions between unrelated types?
Have a sens to have extrinsec conversions which implicitly convert?
Should this convert_to<T> operator be considered as a friend class of T?
I know that this is out of the scope of Boost, but I just wanted to know your opinion before posting to comp.lang.c++.moderated.
Apologize if this has already been discused.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk