Boost logo

Boost :

Subject: Re: [boost] [conversion] How to repere assignement to a variable? (was [property] interest in C# like properties for C++?)
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-10-23 18:42:06

----- Original Message -----
From: "Stewart, Robert" <Robert.Stewart_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, October 22, 2009 4:58 PM
Subject: Re: [boost] [conversion] How to repere assignement to a variable? (was [property] interest in C# like properties for C++?)

> 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".

>> 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. The idea is reasonable, because it can be customized to recognize properties, however implemented, as well as normal data types, to provide a common "assignment syntax" that adapts to the types used.
> 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?

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.

I have posted something related to this recently "[conversion] Motivation for two NEW generic conver_to and assign_to functions" Maybe you can take a look. I'll apreciate your comments.
>> If we want transitive assignation
>> a = b = c;
>> we could do
>> assign_to(a, assign_to(b, c));
>> and if we find this not really readable we can try with
>> tie(a) = tie(b) = c;
> Neither is good, but transitive assignment can be ignored; it is hardly a critical feature. (I rarely use it.)

For the moment I don't have a better proposal.

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