Bug 11707 – "data" property for std.typecons.Typedef?

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-07T07:21:48Z
Last change time
2020-03-21T03:56:32Z
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-12-07T07:21:48Z
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.
Comment #1 by b2.temp — 2017-09-15T05:40:28Z
That's very comic how Typedef can be too strong for you here but too weak there: https://issues.dlang.org/show_bug.cgi?id=11708 You have to learn what you want bearophile.