struct Foo
{
        @property bool empty() const { return p == null; }
        @property auto front() inout { return p; }
        void popFront() { p--; }


        // So far so good? okay, let's define save()..

        auto save() inout { return typeof(this)(this.tupleof); }


        // Now let's implement opApply() using the above ^^

        int opApply(void delegate(size_t, typeof(p)) dg) const
        {
                size_t i = 0;
                int r = 0;

                // So far so good...
                for (auto me = this.save(); !r && !me.empty; me.popFront())
                {
                        // Whoops, won't work -- 'me' is const! :(
                        r = dg(me);
                }

                return r;
        }
}



How do you fix this without duplicating your code?

Reply via email to