Boost logo

Boost :

Subject: Re: [boost] [review] string convert
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-04 13:44:17

Vicente BOTET wrote:
> De : "Stewart, Robert"
> > Vicente BOTET wrote:
> > > De : "Stewart, Robert"
> > > > Vicente BOTET wrote:
> > > > > De : "Stewart, Robert"
> > > 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);
> > >
> >
> > Your assignment operators are not on the target type, but on
> > a converting proxy. Using assign_to() implies that the
> > operation is lhs = rhs, but that's incorrect. The operation
> > is, instead, lhs = f(rhs), where f() applies some
> > transformation to rhs to produce lhs. Hence, "assign_to" is
> > the wrong name.
> Note that the default behavior of assign_to is lhs = rhs. Only
> the assign_to user overloading will make something different
> because in C++ we can not extrinsically the operator=. Think of
> the assign_to overloading as if the user were able to make the
> following free overloading
> C1& operator=(C1&, C2 const&);
> as is not correct in C++. But if it was possible, how would you
> call this operator.

IOW, in your library, f() is a built-in conversion or promotion when possible, which is good. When it isn't possible, then it is some conversion operation that must be applied. Your idea of a free assignment operator is interesting. It certainly does fit the model pretty well. However, C++ programmers don't think in terms of an extrinsic assignment operator but of conversion functions, factory functions, etc. I'm still not completely comfortable with "assign_to" but you're making headway!

> Following your reasoning convert_to will not be a good name as
> in my library the default behavior it implies returning
> Target(rhs), that is calling the conversion operator/conversion
> constructor. But this is not the case when the user overload
> the convert_to function as the returned type should be
> assimilated to some transformation f of the rhs to get a
> Target. something like Target(f(rhs)).

Nope. "convert_to" is "f" in my discussion above. It *is* the conversion function, regardless of how it is implemented.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at