Hello,
I have been playing around with templated range. I am not quite sure why the following code does not work:

template isIntLike(T) {
        enum isIntLike = is(typeof({
                T t = 0;
                t = t+t;
                // More if needed
        }));
}

auto fib(T = int)() if (isIntLike!T) {
        struct Fib {
                T a, b;
                
                T front() {return b;}
                bool empty() {return false;}
                
                void popFront() {
                        T c = a+b;
                        a = b;
                        b = c;
                }
        }
        return Fib(0, 1);
}

This code does not work if I call fib!BigInt(). The compiler complains that 0 cannot be implicitly converted into a BigInt. It is right of course, but BigInt has a constructor accepting a long, so shouldn't this work anyway? What is the correct way to write this function?

Thank you all for your time,
Michael

Reply via email to