Copying a delegate
Jonathan M Davis
jmdavisProg at gmx.com
Mon Sep 20 02:08:32 PDT 2010
On Monday 20 September 2010 01:08:25 Kagamin wrote:
> Jonathan M Davis Wrote:
> > delegate by definition has context which is not going to be copied. So,
> > any functon pointer or delegate that you have must refer to a function
> > which is logically pure, otherwise any algorithm that relies on save is
> > not going to work correctly.
>
> If phobos causes subtle bugs, it's a bug worth filing.
Except that it's not really phobos' fault. The problem is that once part of the
state of a struct or class is a delegate, you *can't* copy it. As far as I know,
there is no way in the language to do it. A forward range's save property is
supposed to give you a copy of the range which copies the state specific to
iterating the range such that you can iterate the copy to your heart's content
without affecting the original's ability to iterate. But if a delegate is part of
the iteration state of a range, and that delegate isn't logically pure, the copy
is going to use that delegate and alter the state of the original range, because
they share that delegate. I don't think that there's anything Phobos can do
about it. It's a limitation of delegates.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list