[cfe-dev] question about OpaqueValueExpr (was: injecting a member function)
eric at boostpro.com
Tue Feb 22 01:37:00 PST 2011
On 2/19/2011 1:18 AM, John McCall wrote:
> On Feb 18, 2011, at 1:49 AM, Eric Niebler wrote:
>> On 2/18/2011 3:41 PM, John McCall wrote:
>>> let tmp = obj in
>>> tmp.setProp(tmp.getProp() + 1)
>> In practical terms, that means that, when evaluating tmp, evaluate obj
>> (once), and thereafter all other times tmp is evaluated, just use the
>> result already computed. And this Just Works wrt lvalues and rvalues.
> Right. When creating the OVE, you give it a type, value kind, and
> value object kind matching the expression it gets bound to.
Here's a question. What if I create a OpaqueValueExpr, and I want it to
be an lvalue (so I can mutate it in place), but the expression it gets
bound to is actually an rvalue? Will that work? Or can I cast an rvalue
to an lvalue somehow and bind the OVE to that?
The reason I ask is because I want this:
a.b += 42
to be rewritten as:
let tmp = a
in tmp.set(tmp.get() += 42)
tmp.get() will (probably) be an rvalue, but for feature parity with MS,
I need to use += instead of the (obvious and simpler) +.
More information about the cfe-dev