digitalmars.D - std.metastrings.ToString! problems
- asd (12/12) Jul 23 2009 I'm trying to write basic compile-time function:
- Daniel Keep (3/19) Jul 23 2009 That's because n isn't a compile-time constant. You can't instantiate a
- BCS (3/24) Jul 23 2009 that includes "runtime variables" used in CTFE (this is because CTFE fun...
- asd (2/11) Jul 24 2009 In this case value of n is possible to know at compile time - it depends...
- Ary Borenszweig (3/16) Jul 24 2009 So write:
I'm trying to write basic compile-time function: string usedForMixin() { int n=0; /* do stuff */ return "int x = " ~ std.metastrings.ToString!(n) ~ ";"; } However I'm getting: /usr/local/bin/../src/phobos/std/metastrings.d(104): Error: expression cast(long)n is not a valid template value argument If I change int to long: /usr/local/bin/../src/phobos/std/metastrings.d(87): Error: expression n < 0L is not constant or does not evaluate to a bool (D2, OS X)
Jul 23 2009
asd wrote:I'm trying to write basic compile-time function: string usedForMixin() { int n=0; /* do stuff */ return "int x = " ~ std.metastrings.ToString!(n) ~ ";"; } However I'm getting: /usr/local/bin/../src/phobos/std/metastrings.d(104): Error: expression cast(long)n is not a valid template value argument If I change int to long: /usr/local/bin/../src/phobos/std/metastrings.d(87): Error: expression n < 0L is not constant or does not evaluate to a bool (D2, OS X)That's because n isn't a compile-time constant. You can't instantiate a template with runtime variables.
Jul 23 2009
Reply to Daniel,asd wrote:that includes "runtime variables" used in CTFE (this is because CTFE functions are also normal runtime functions).I'm trying to write basic compile-time function: string usedForMixin() { int n=0; /* do stuff */ return "int x = " ~ std.metastrings.ToString!(n) ~ ";"; } However I'm getting: /usr/local/bin/../src/phobos/std/metastrings.d(104): Error: expression cast(long)n is not a valid template value argument If I change int to long: /usr/local/bin/../src/phobos/std/metastrings.d(87): Error: expression n < 0L is not constant or does not evaluate to a bool (D2, OS X)That's because n isn't a compile-time constant. You can't instantiate a template with runtime variables.
Jul 23 2009
In this case value of n is possible to know at compile time - it depends only on compile-time input. I'm not going to use this function at run time. Too bad I can't declare that :(that includes "runtime variables" used in CTFE (this is because CTFE functions are also normal runtime functions).n < 0L is not constant or does not evaluate to a bool (D2, OS X)That's because n isn't a compile-time constant. You can't instantiate a template with runtime variables.
Jul 24 2009
asd wrote:So write: const int n = 0;In this case value of n is possible to know at compile time - it depends only on compile-time input. I'm not going to use this function at run time. Too bad I can't declare that :(that includes "runtime variables" used in CTFE (this is because CTFE functions are also normal runtime functions).n < 0L is not constant or does not evaluate to a bool (D2, OS X)That's because n isn't a compile-time constant. You can't instantiate a template with runtime variables.
Jul 24 2009