Boost logo

Boost :

Subject: Re: [boost] [conversion] How to repere assignement to a variable? (was [property] interest in C# like properties for C++?)
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-10-26 09:19:38

vicente.botet wrote:
> From: "Stewart, Robert" <Robert.Stewart_at_[hidden]>
> > vicente.botet wrote:
> >>
> >> in the thread about C# like properties we were talking about
> >> the advantage to be able to repere assignation to properties.
> >
> > I assume by "repere assignation" you mean, in English,
> > "represent assignment." ("Assignation" is not used,
> > normally, as a synonym for "assignment.")
> Sorry for my bad English. I meant "locate/recognize assignments".

That's not a problem -- your English is better than my French. I just wanted to be sure I understood you.

> >> I said that, another way to repare the assignments is to use
> >> a free function assign_to, like we use the free function
> >> swap, or the cast family functions.
> >>
> >> assign_to(a.p_X, 1);
> >>
> >> assign_to call by default the assignment operator.
> >
> > That's a reasonable default while permitting customization.
> However, operator = can be likewise customized and is
> idiomatic for assignment. Why create a new name?
> Operator can only be defined on the Traget class and can not
> be used between unrelated types. When you have two types
> implemented by two independent libraries but representing the
> same concept, (not C++ concept), you need to convert one to
> the other when you need to use both libraries. The typical
> ewample is the Time. How many time representations do you
> know? How many conversion from one representation to the
> other have yo needed?

You raised this in the context of properties. Using proxies in a property implementation means that the conversions can be done via assignment. Whether the assignment operator uses custom functions, traits, or something like your assign_to(), is quite another matter.

For properties to work like all the properties I've seen -- in other languages, of course -- assignment is the way to go, possibly augmented with some explicit conversion operation.

> I would like C++ be updated so extrinsic converison operators
> and assignement are allowed, but this is not yet the case. It
> is for this reason have propose to use a function insead of
> an operator.

In other contexts, this is certainly sensible, and I can even understand supporting properties in the assign_to() framework.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
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