writing iterators without code duplication. inout?
pompei2
pompei2 at gmail.com
Thu Dec 22 00:04:29 PST 2011
> int delegate(int delegate(ref int)) doIter() const
> {
>74 return (int delegate(ref int) dg)
> {
> cast(typeof(this))(this).doIter()
>77 (
>78 (ref int i)
> {
> int copy = i; dg(copy);
> }
> );
> }
> }
I see what you are doing there. Unfortunately, the innermost
delegate (the one doing the copy trick) somehow got @system
attribute, which leads to the following compile errors (I added
line numbers and reordered your code in the citation above):
constiter.d(78): Error: cannot implicitly convert expression
(__dgliteral2) of type void delegate(ref int i) @system to int
delegate(ref int)
constiter.d(77): Error: cast has no effect in expression
(cast(const(Container))this.doIter()((__error)))
constiter.d(74): Error: cannot implicitly convert expression
(__dgliteral1) of type void delegate(int delegate(ref int) dg)
@system to int delegate(int delegate(ref int))
Where does this @system come from? How do I get rid of it?
> Until
> int delegate(ref inout int) opApply() inout;
> and
> int delegate(int delegate(ref inout int)) doIter() inout;
> are made to work. (I actually don't know if there is any
> obstacles to do this).
Can you point me to the bugreport so I can vote for it? I'm not
sure if it is #4838 or if they are unrelated.
More information about the Digitalmars-d-learn
mailing list