Re: T.zero and T.one for numeric types

2015-04-17 Thread Biotronic via Digitalmars-d
On Friday, 17 April 2015 at 13:33:36 UTC, Adam D. Ruppe wrote: On Friday, 17 April 2015 at 13:27:19 UTC, Biotronic wrote: void foo(T)(T a) {} foo!T(0); Does foo(T(0)); work? It seems like it should void foo(T)(T a) {} import std.bigint; import std.complex; void main() {

T.zero and T.one for numeric types

2015-04-17 Thread Biotronic via Digitalmars-d
I've been writing a lot of generic code lately that has to deal with various kinds of numbers, and have near been driven nuts by the fact there is no uniform way to get a zero or one. Consider: void foo(T)(T a) {} foo!T(0); Does this work with all built-in numeric types? Yes. Does it

Re: T.zero and T.one for numeric types

2015-04-17 Thread Adam D. Ruppe via Digitalmars-d
On Friday, 17 April 2015 at 13:27:19 UTC, Biotronic wrote: void foo(T)(T a) {} foo!T(0); Does foo(T(0)); work? It seems like it should void foo(T)(T a) {} import std.bigint; import std.complex; void main() { foo(BigInt(0)); foo(float(0)); foo(int(0));

Re: T.zero and T.one for numeric types

2015-04-17 Thread ketmar via Digitalmars-d
On Fri, 17 Apr 2015 13:27:18 +, Biotronic wrote: would work. But why can't I instead, for every numeric type, simply write foo(BigInt.zero); foo(float.one); foo(Complex!float.zero); foo(Rational!BigInt.one); foo(Meters.zero); Omens.sixsixsix... signature.asc Description:

Re: T.zero and T.one for numeric types

2015-04-17 Thread w0rp via Digitalmars-d
On Friday, 17 April 2015 at 13:27:19 UTC, Biotronic wrote: I've been writing a lot of generic code lately that has to deal with various kinds of numbers, and have near been driven nuts by the fact there is no uniform way to get a zero or one. Consider: void foo(T)(T a) {} foo!T(0);