On 5/28/2013 1:32 AM, Jonathan M Davis wrote:
On Tuesday, May 28, 2013 08:55:10 Russel Winder wrote:
Arising from a thread on the GoLangNuts email list, I wrote the
following:
import std.algorithm: reduce;
import std.bigint;
import std.range: iota;
import std.stdio: writeln;
int main(immutable string[] args) {
foreach (int i; iota(10, 50, 10)) {
writeln(reduce!"a * b"(BigInt(1), iota(BigInt(1),
BigInt(i))));
}
return 0;
}
Sadly the compiler refuses to acknowledge that iota works for BigInt. My
first assumption is that my code is wrong. My second assumption is that
std.range doesn't work with real integers — as opposed to those pesky
limited hardware things ;-)
The problem is simple enough. iota doesn't currently try and work with any
type that has addition (like it probably should). It specifically only works
with integers, floating point values, and pointers. BigInt is not an integral
type as far as std.traits is concerned. Only the built-in integer types are
integral types as far as it's concerned. What's required is a different trait
that tests that a type has arithmetic operations or for iota to simply test
that the type has + or += or whatever it needs internally. Then iota can have
an overload that works on any type that has the necessary operations.
- Jonathan m Davis
Please enter this into Bugzilla.