Strings concatenated at compile time?

2014-05-01 Thread Unwise via Digitalmars-d-learn
In the following example from the documentation, are strings concatenated at compile time? template foo(string s) { string bar() { return s ~ betty; } } void main() { writefln(%s, foo!(hello).bar()); // prints: hello betty }

Re: Strings concatenated at compile time?

2014-05-01 Thread anonymous via Digitalmars-d-learn
On Thursday, 1 May 2014 at 10:42:36 UTC, Unwise wrote: In the following example from the documentation, are strings concatenated at compile time? template foo(string s) { string bar() { return s ~ betty; } } void main() { writefln(%s, foo!(hello).bar()); // prints: hello betty } I

Re: Strings concatenated at compile time?

2014-05-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Thu, 01 May 2014 11:12:41 + anonymous via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Thursday, 1 May 2014 at 10:42:36 UTC, Unwise wrote: In the following example from the documentation, are strings concatenated at compile time? template foo(string s

Re: Strings concatenated at compile time?

2014-05-01 Thread bearophile via Digitalmars-d-learn
Jonathan M Davis: If you want it to be guaranteed, you'd do something like template foo(string s) { enum foo = s ~ betty; } A more general solution is to wrap the concatenation with a call to: alias ctEval(alias expr) = expr; Use: string bar() { return ctEval!(s ~ betty); } Bye,