[conversion] How to repere assignement to a variable? (was [property] interest in C# like properties for C++?)

Hi, in the thread about C# like properties we were talking about the advantage to be able to repere assignation to properties. 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. 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; tie is a template function returning an ca_wrapper. template <typename T> ca_wrapper <T> tie(T& r) { return ca_wrapper<T>(r); } ca_wrapper is responsable to transforming the assignation and operator conversion on a call to assign_to and no more. template <typename T> class ca_wrapper { T& ref_; public: ca_wrapper(T& r) : ref_(r) {} template <typename U> T& operator =(U const& u) { return assign_to(ref_, u); } template <typename U> operator U() { return convert_to(ref_, u); } }; The advantage of having a specific function is that we can specialize the assign_to function for unrelated classes. The Boost.Conversion library (on the review schedule) defines two free functions convert_to and assign_to which by default use the conversion operator and the assignment. We can see convert_to as a getter and assign_to as a setter. The major advantage is that with a uniform syntax, the user can however specialize them to do conversion and assignations between unrelated types. I don't know if tie is a good name to manage with assignation of a variable, I have taken the name from the Boost.Tuple? Regards, _____________________ Vicente Juan Botet Escribá P.S. tie and ca_wrapper are new features of Boost.Conversion v.0.3

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.")
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?
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.) _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com 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.

Hi, ----- Original Message ----- From: "Stewart, Robert" <Robert.Stewart@sig.com> To: <boost@lists.boost.org> 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. Best, Vicente

vicente.botet wrote:
From: "Stewart, Robert" <Robert.Stewart@sig.com>
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@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com 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.
participants (2)
-
Stewart, Robert
-
vicente.botet