If line 9 of the program is commented out, it runs fine.
Otherwise lots of error messages which don't pan out for me.
I tried changing Negative.front to be const, which didn't help.
I am not quite sure what the error messages are telling me.

Thank you for your assistance!

```
C:\D\dmd2\windows\bin64\..\..\src\phobos\std\range\package.d(4560): Error: 
mutable method `app.Negative!(Take!(FibonacciSeries)).Negative.front` is not 
callable using a `const` object
                return _current.front;
                       ^
c:\dev\D\81 - 90\c82_1e_InputRange_does_support_cycle_with_save\source\app.d(44): Consider adding `const` or `inout` here
    auto front()
         ^
C:\D\dmd2\windows\bin64\..\..\src\phobos\std\range\package.d(4695): Error: 
template instance `std.range.Cycle!(Negative!(Take!(FibonacciSeries)))` error 
instantiating
    else return Cycle!R(input);
                ^
c:\dev\D\81 - 90\c82_1e_InputRange_does_support_cycle_with_save\source\app.d(9): instantiated from here: `cycle!(Negative!(Take!(FibonacciSeries)))`
            .cycle      // ← compilation ERROR
            ^
```

source/app.d
```
import std.stdio;
import std.range;

void main()
{
        writeln(FibonacciSeries()
                        .take(5)
                        .negative
                        .cycle      // ← compilation ERROR
                        .take(10));
}

struct FibonacciSeries
{
        int current = 0;
        int next = 1;
        enum empty = false;
        int front() const
        {
                return current;
        }

        void popFront()
        {
                const nextNext = current + next;
                current = next;
                next = nextNext;
        }

        FibonacciSeries save() const
        {
                return this;
        }
}

struct Negative(T) if (isInputRange!T)
{
        T range;
        bool empty()
        {
                return range.empty;
        }

        auto front()
        {
                return -range.front;
        }

        void popFront()
        {
                range.popFront();
        }

        static if (isForwardRange!T)
        {
                Negative save()
                {
                        return Negative(range.save);
                }
        }
}

Negative!T negative(T)(T range)
{
        return Negative!T(range);
}
```

Reply via email to