View mode: basic / threaded / horizontal-split · Log in · Help
May 25, 2007
evaluate string functions at compile time?
Atm I could make use of some CTFE, but at least some of the functions
in std.string seem to be not evaluable at compile time.
Is it generally impossible to run library functions at compile time?
If not what would be the easiest way to use split, splitlines etc.

Okay these 2 are bad example because they would be easily writeable.
But for example RE's are a problem and so are format strings.
Not even the templated version de help me if the string they are
working on is not const in the CTF.

Any ideas?
If its all to hard I think ill switch to write a simple program that
does the magic-file-to-d-source conversion and include it in my build
step.

Henning

-- 
GPG Public Key: http://keyserver.veridis.com:11371/search?q=0x41911851
Fingerprint: 344F 4072 F038 BB9E B35D  E6AB DDD6 D36D 4191 1851
May 25, 2007
Re: evaluate string functions at compile time?
Henning Hasemann wrote:
> Atm I could make use of some CTFE, but at least some of the functions
> in std.string seem to be not evaluable at compile time.
> Is it generally impossible to run library functions at compile time?

One has to author a function *very carefully* to ensure that it'll be evaluated as "const only" (compile-time function). 
 I don't know if Walter refactored std.string with CTFE in mind, so if you have been able to get some of those to work 
at compile-time, it might just be dumb luck.

So generally speaking, it's best to assume that a function isn't compatible with CTFE unless explicitly stated in the 
code/documentation.

> If not what would be the easiest way to use split, splitlines etc.

If absolutely must have compile-time equivalents for these, then you probably need to roll your own (or refactor the 
ones in std.string).

> Okay these 2 are bad example because they would be easily writeable.
> But for example RE's are a problem and so are format strings.
> Not even the templated version de help me if the string they are
> working on is not const in the CTF.

If the string you're working with is not const, then you're out of luck.  You need to have const data in order for CTFE 
to work correctly.

> Any ideas?
> If its all to hard I think ill switch to write a simple program that
> does the magic-file-to-d-source conversion and include it in my build
> step.

Sometimes, that's just the thing to do - take the earlier compile-time "id generation" thread for example.

-- 
- EricAnderton at yahoo
Top | Discussion index | About this forum | D home