|
Boost : |
Subject: Re: [boost] [review] string convert
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-05-04 08:57:18
> Message du 04/05/11 13:12
> De : "Stewart, Robert"
> A : "'boost_at_[hidden]'"
> Copie à :
> Objet : Re: [boost] [review] string convert
>
> Vicente BOTET wrote:
> > De : "Stewart, Robert"
> [repeat several times!]
> What your three options don't address, then, is indicating conversion failure, without an exception, for a type with neither a default constructor nor a usable sentinel value. That was the purpose of Vladimir's result type: it could be queried for success and for the value.
Please, check the post around May 03, 2011; 10:09pm that includes a file with the complete post without angle brackets issues. There you will find all the cases.
> > > > assign_to is the functional for of operator= (assign). This
> > > > operator can accept any type on its lhs, making a
> > > > conversion. I think the name assign_to respect this schema.
> > >
> > > I'm not arguing why you have the function, I'm just telling
> > > you that I don't find the name to be good.
> >
> > Would you have a better name?
>
> Not presently. I need to think about it more, but first...
>
> > > I also don't thing assignment for conversions is appropriate.
> >
> > Well, this is part of the language, I'm quite sure the C++
> > standard and Boost uses this kind of assignations. As a generic
> > function emulating extrinsic assignation you should I must
> > follows the standard mechanism conventions. It is up to the
> > user to overload or not this function which by default relies
> > on the operator=.
>
> I haven't looked at the design of your library, but presumably these assignment operators are on a conversion type. Your conversion type's state is being set from another type in the various assignment operators, which is the normal sense of assignment, but your purpose of doing so is simply to provide the source value in order to extract it subsequently as the target type. That seems an abuse of assignment.
If you have a class C1 you can define the following operator
C1& operator=(C2 const& rhs);
As I understand this, we are converting a C2 to a C1 via an assignment. The assign_to function is a way do it extrinsically, i.e. outside any of the classes C1, C2.
C1& assign_to(C1 & lhs, C2 const& rhs);
We can say assign_to is to C1& operator=(C1&,C2const&) as boost::swap(C&lhs,C&rhs) is to C::swap(C& rhs).
convert_to is the counterpart of the explicit conversion operator (or explicit constructor)
If we had the possibility to overload operator= as a free function I will not needed to add an assign_to function.
If we had the possibility to overload explicit conversion operators as a free function I will not needed to add an conver_to function.
So we can say Boost.Conversion is an emulation of these operator overloading as free functions.
Best,
Vicente
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk