Boost logo

Boost :

Subject: Re: [boost] [TypeErasure] references
From: Chapman, Alec (archapm_at_[hidden])
Date: 2012-07-30 13:51:06


On 7/26/2012, 5:45 PM, Chapman, Alec wrote:
> > The problem is that there are significant differences between
> > references and values. This is okay for Boost.Function, because
> > Boost.Function doesn't expose ant mutating operations. However, in
> > the more general case this behavior is too error prone. Just think
> > about what would happen if we allowed using boost::ref for
> > any_iterator. Some Algorithms assume that they can make copies of iterators
> and that these iterators are independent of each other.
>
> These are exactly the sorts of algorithms I have in mind. What I am suggesting
> is that the original object is held by reference, but when a copy is made the
> underlying object is copied as well. With your method I do not see a way to
> capture by reference and then pass that object to an algorithm that does not
> have special logic to handle Boost.TypeErasure.
>
> Perhaps the false parallel with Boost.Function would be confusing. I have also
> done it by overloading the constructor with a dummy parameter:
>
> int i = 0;
> any<requirements> x(i, type_erasure::as_reference); // x holds a pointer to i
> any<requirements> y(x); // y allocates a new
> integer and initializes it with i
> ++y; // i is still 0
>

Hi Steven,
Have you had a chance to consider this? Please let me know if something I'm suggesting isn't clear or if there is already a way to achieve this with your library.
Alec


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