evaluate string functions at compile time?

Pragma ericanderton at yahoo.removeme.com
Fri May 25 13:18:05 PDT 2007


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



More information about the Digitalmars-d mailing list