
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Thursday, July 26, 2012 4:44 PM To: boost@lists.boost.org Subject: Re: [boost] [TypeErasure] references
AMDG
On 07/26/2012 10:31 AM, Chapman, Alec wrote:
Hi Steven,
I have a somewhat-generic type erasure class that I would like to switch to yours. The main difficulty I can see is in the way capturing by reference is handled. The approach I take in my class is to pass a boost::reference_wrapper to the constructor:
<snip>
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
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost