My first D module - Critiques welcome.
monarch_dodra
monarchdodra at gmail.com
Tue Dec 24 07:02:01 PST 2013
On Monday, 23 December 2013 at 22:46:24 UTC, Gary Willoughby
wrote:
> I like it and it seems you are grasping D well. I wonder if the
> entire implementation could be done using templates and all
> done at compile time? It would be interesting to explore.
>
> int year = fromRoman!("DXLIX");
> string year = toRoman!(2013);
>
> Very similar to how [octal][1] is implemented;
>
> [1]: http://dlang.org/phobos/std_conv.html#.octal
I was about to submit an "eval" function which would render this
kind of stuff obsolete. The idea is that since D has CTFE
built-in, such templates are not needed, since you can do:
enum year = fromRoman("DXLIX");
The "problem" is that is you want a *variable* that is
initialized *to* a certain value, but don't want to pay for the
initialization, you have to write:
enum yearEnum = fromRoman("DXLIX");
int year = yearEnum;
"eval" (which is documented in the docs, but isn't in phobos),
would allow:
int year = eval!(fromRoman!("DXLIX"));
I think such a generic solution is a better approach, and
generally useful regardless of what you are dealing with.
More information about the Digitalmars-d-learn
mailing list