On Sun, 20 May 2012 20:07:04 -0400, Mehrdad <[email protected]> wrote:

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?

This is yet another cry for tail-const.

It's very obvious we need a clean solution for tail-const before the const story is finished.

The answer for now?  Don't make opApply const.

-Steve

Reply via email to