digitalmars.D.learn - Compile time strings auto concatenation!?
- Ilya (11/11) Nov 20 2015 Can DMD frontend optimize
- Justin Whear (10/25) Nov 20 2015 Yes this occurs as part of the constant folding I believe.
- Tofu Ninja (7/18) Nov 21 2015 If you really want to make sure it is concatenated at compile
- Marc =?UTF-8?B?U2Now7x0eg==?= (5/16) Nov 21 2015 At least for string (and array?) literals, it's now guaranteed to
Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ?
Nov 20 2015
On Fri, 20 Nov 2015 20:39:57 +0000, Ilya wrote:Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ?Yes this occurs as part of the constant folding I believe. $ cat test.d enum Double(string S) = S ~ S; void main(string[] args){ assert(args.length, "Text " ~ Double!"+" ~ __FUNCTION__); } $ dmd test.d $ strings test | grep Text Text ++test.main
Nov 20 2015
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote:Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ?If you really want to make sure it is concatenated at compile time, just do this: ... enum CT(alias S) = S; assert(condition, CT!("Text " ~ Double!"+" ~ ___FUNCTION__)); // Must be evaluated at CT no matter what
Nov 21 2015
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote:Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ?At least for string (and array?) literals, it's now guaranteed to happen at compile time. It was changed in order to get rid of the error-prone "concatenation by juxtaposition" feature inherited from C. I'm not sure it also applies to non-literals, though.
Nov 21 2015