Boost logo

Boost :

From: Gregory Colvin (gregory.colvin_at_[hidden])
Date: 2004-06-06 12:41:39


On Jun 6, 2004, at 10:12 AM, Eric Niebler wrote:
> Eric Niebler wrote:
>> Eric Niebler wrote:
>>>
>>> There is another solution. Give rules value semantics by default as
>>> I suggest, but require people to use special syntax to get reference
>>> semantics.
>> I hate replying to myself. ;-) I realize this doesn't give true value
>> semantics. A rule which refers to itself (that is, it indirectly
>> stores a pointer to itself) cannot be copied around and put inside
>> containers and whatnot. Then I thought that it could be solved with
>> an extra layer of indirection -- shared_ptr to a shared_ptr (ugh!)
>> but then you have problems with cyclic references. Hence Joel's
>> comment about garbage collection -- he's probably been through this
>> thought process before.
>> I think I need to think it out again.
>
>
> Here I go, replying to myself *again*. I've rethought this and come up
> with a new scheme whereby rules (or in xpressive's case regexes) can
> have both value *and* reference semantics. A good analogy would be a
> pointer. You can copy pointers freely, creating aliases. You can
> dereference the pointer and assign through it, changing all the
> aliases.
> This is how regex objects in xpressive work right now (it's an
> experiment).
>
> In addition, I have solved the cyclic/dangling reference problem. A
> regex can refer to other regexes or itself and it tracks changes to
> its referenced regexes. It lets you copy regex objects freely, even
> putting them in containers, and they keep their references alive. It
> works with nothing more sophisticated than shared_ptr and weak_ptr --
> no garbage collection is necessary. No cycles are created ever, so no
> cycles need to be collected.
>
> There are only two questions:
> (1) is the rule-as-pointer metaphor acceptable? and
> (2) can we find a palatable syntax?
>
> The syntax issue is this: if we take assign to be shallow (creating
> aliases) we need a different syntax for deep assign. I am using *= to
> mean deep-assign. Perhaps there is a better solution.

*x = *y

?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk