[Issue 11707] New: "data" property for std.typecons.Typedef?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 7 07:21:49 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11707
Summary: "data" property for std.typecons.Typedef?
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2013-12-07 07:21:48 PST ---
Here std.typecons.Typedef is used to define a strong type, but later it can't
be used as array index:
void main() {
import std.typecons: Typedef;
alias Idx = Typedef!uint;
int[5] data;
auto i = Idx(1);
data[i] = 10;
}
dmd 2.065alpha gives:
temp.d(6): Error: cannot implicitly convert expression (i) of type
Typedef!(int, 0) to uint
A simple solution is to cast:
data[cast(size_t)i] = 10;
But in some cases this could be better, a property for Typedef, that returns
the wrapped data:
data[i.data] = 10;
This is less greppable than the cast(), but I think it's explicit enough.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list