Bug 8158 – std.algorithm.min fails to compile with user-defined types
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-29T02:36:00Z
Last change time
2015-06-09T05:14:50Z
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2012-05-29T02:36:43Z
This code
import std.algorithm;
import std.datetime;
import std.stdio;
void main()
{
writeln(min(Date(2012, 5, 7), Date(2011, 2, 9)));
writeln(max(Date(2012, 5, 7), Date(2011, 2, 9)));
}
should print
2011-Feb-09
2012-May-07
Instead, it fails to compile with
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/traits.d(4289): Error: incompatible types for ((min()) == (0)): 'Date' and 'int'
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/traits.d(4289): Error: error evaluating static if expression
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(5035): Error: template instance std.traits.mostNegative!(Date) error instantiating
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(5055): Error: template instance std.algorithm.MinType!(Date,Date) error instantiating
q.d(7): instantiated from here: min!(Date,Date,)
q.d(7): Error: template instance std.algorithm.min!(Date,Date,) error instantiating
or, if pull request #611 ( https://github.com/D-Programming-Language/phobos/pull/611 ) is pulled in, it fails to compile with
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(5035): Error: template instance mostNegative!(Date) mostNegative!(Date) does not match template declaration mostNegative(T) if (isNumeric!(T) || isSomeChar!(T))
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(5035): Error: template instance mostNegative!(Date) mostNegative!(Date) does not match template declaration mostNegative(T) if (isNumeric!(T) || isSomeChar!(T))
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(5037): Error: template instance mostNegative!(Date) mostNegative!(Date) does not match template declaration mostNegative(T) if (isNumeric!(T) || isSomeChar!(T))
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(5037): Error: template instance mostNegative!(Date) mostNegative!(Date) does not match template declaration mostNegative(T) if (isNumeric!(T) || isSomeChar!(T))
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(5055): Error: template instance std.algorithm.MinType!(Date,Date) error instantiating
q.d(7): instantiated from here: min!(Date,Date,)
q.d(7): Error: template instance std.algorithm.min!(Date,Date,) error instantiating
In either case, the std.algorithm.min is failing to compile. max actually works if you comment out the call to min, but min is broken.