Implicit Conversions in Struct Construction
Michael
pongad at gmail.com
Thu Oct 18 20:44:10 PDT 2012
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
More information about the Digitalmars-d-learn
mailing list