Optionally strongly typed array indexes

Philippe Sigaud via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 6 12:59:11 PDT 2014


> Also true, though as a side note, I think a library solution for this could
> be quite nice:
>
>   enum newton = 1.as!"kg*m/s^2";  // One possibility.
>   enum newton = 1*kg*m/square(s); // Another.

Sorry to intrude, but you can also get:

enum newton = 1.kg/m/s^^2;

Which is quite readable. In this case, 'kg', 'm' and 's' are factory
functions. The '1.kg' part is just UFCS in action.

For the subjacent return type, you can also define the power operator,
at least for integers.


More information about the Digitalmars-d mailing list