On Wednesday, 11 October 2017 at 14:28:32 UTC, Meta wrote:
On Wednesday, 11 October 2017 at 09:56:52 UTC, Igor wrote:
On Wednesday, 11 October 2017 at 08:35:51 UTC, Walter Bright
wrote:
On 10/10/2017 3:16 PM, sarn wrote:
Works even better in D because it can run at compile time.
Yes, I see no need for a language feature what can be easily
and far more flexibly done with a regular function -
especially since what |q{ and -q{ do gives no clue from the
syntax.
You are right. My mind is just still not used to the power of
D templates so I didn't think of this. On the other hand that
is why D is still making me say "WOW!" on a regular basis :).
Just to confirm I understand, for example the following would
give me compile time stripping of white space:
template stripws(string l) {
enum stripws = l.replaceAll(regex("\s+", "g"), " ");
}
string variable = stripws(q{
whatever and ever;
});
And I would get variable to be equal to " whatever and ever;
". Right?
Even better, you could write the same code that you would for
doing this at runtime and it'll Just Work:
string variable = q{
whatever and ever;
}.replaceAll(regex(`\s+`, "g"), " ");
I tried this but Disassembly view shows:
call std.regex.regex!string.regex
and
call std.regex.replaceAll!(string, char,
std.regex.internal.ir.Regex!char).replaceAll
which means that replaceAll with regex is done at runtime, not
compile time. Also when I just added enum in front of string
variable then I got this:
Error: malloc cannot be interpreted at compile time, because it
has no available source code