Compile-time conversions from string to integer, real, etc.
Don Clugston
dac at nospam.com.au
Fri Apr 13 14:49:29 PDT 2007
Don Clugston wrote:
> Walter Bright wrote:
>> Don Clugston wrote:
>>> In std.metastring there are functions to convert integers to strings
>>> at compile time,
>>
>> Can these be replaced with .stringof ?
> Yup. It should probably be wrapped in a deprecated{} now. As should
> std.math2.
For example:
template toString(real x)
{
const char [] toString=x.stringof;
}
Unfortunately, none of these work inside a CTFE function. The problem
is, that a CTFE function has to also work at runtime, and so it can't
use compile-time variables in template value arguments (and it can't
index tuples, etc). These kinds of operations are the only ones where
template metaprogramming still survives.
More information about the Digitalmars-d
mailing list