On Tue, 04 May 2010 21:55:53 -0400, Michel Fortin <michel.for...@michelf.com> wrote:
        // String version: can slice
        string readUntil(isAtEndPredicate)(ref string input) {
                string savedInput;
                while (!input.empty && isAtEndPredicate(input.front)) {
                        input.popFront();
                }
                return savedInput[0..$-input.length];
        }

What about using forward ranges and take?

        // String version: can slice
        Take!T readUntil(isAtEndPredicate, T)(ref T input) if(isForwardRange!T) 
{
                auto savedInput = input;
                size_t n = 0;
                while (!input.empty && isAtEndPredicate(input.front)) {
                        input.popFront();
                        n++;
                }
                return take(savedInput,n);
        }

Reply via email to