Bug 5501 – Variant wrongly assumes that an object's length property returns a size_t
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-01-29T00:59:00Z
Last change time
2013-01-08T01:22:43Z
Assigned to
andrei
Creator
dransic
Comments
Comment #0 by dransic — 2011-01-29T00:59:57Z
The following code doesn't compile. I hit the problem when using std.datetime.Interval (which length returns a Duration).
import std.variant;
struct Foo {
double length() {
return double.init;
}
}
unittest {
Foo foo;
Variant v = foo;
}
Comment #1 by andrei — 2013-01-08T01:13:47Z
This is by design. The length name is special and defined to return size_t compulsively. A possible solution would be to rename std.datetime.Interval. Will cc jmdavis.
Comment #2 by dransic — 2013-01-08T01:22:43Z
(In reply to comment #1)
> This is by design. The length name is special and defined to return size_t
> compulsively. A possible solution would be to rename std.datetime.Interval.
> Will cc jmdavis.
I agree. But that makes the length property a quasi-keyword and I think it should be better documented, even if it is already used as such in practice.