Re: How to avoid ctRegex (solved)

2016-08-27 Thread ag0aep6g via Digitalmars-d-learn
On 08/27/2016 07:35 PM, cy wrote: When I saw `auto a = b;` at the module level, I thought that b had to be something you could evaluate at compile time. That's right. But I guess it can be a runtime calculated value, acting like it was assigned in a a static this() clause, No, that's not ri

Re: How to avoid ctRegex (solved)

2016-08-27 Thread David Nadlinger via Digitalmars-d-learn
On Saturday, 27 August 2016 at 17:47:33 UTC, Dicebot wrote: But actual value of that Regex struct is perfectly known during compile time. Thus it is possible and fine to use it as initializer. You can use any struct or class as initializer if it can be computed during compile-time. Yes, regex

Re: How to avoid ctRegex (solved)

2016-08-27 Thread Dicebot via Digitalmars-d-learn
On Saturday, 27 August 2016 at 17:35:04 UTC, cy wrote: On Wednesday, 24 August 2016 at 05:29:57 UTC, ag0aep6g wrote: The plain regex function doesn't have such a requirement. It also works with a pattern that's generated at run time, e.g. from user input. But you can use it with a compile time

Re: How to avoid ctRegex (solved)

2016-08-27 Thread cy via Digitalmars-d-learn
On Wednesday, 24 August 2016 at 05:29:57 UTC, ag0aep6g wrote: The plain regex function doesn't have such a requirement. It also works with a pattern that's generated at run time, e.g. from user input. But you can use it with a compile time constant, too. And it works in CTFE then, but it does n

Re: How to avoid ctRegex (solved)

2016-08-24 Thread Seb via Digitalmars-d-learn
On Wednesday, 24 August 2016 at 05:29:57 UTC, ag0aep6g wrote: On 08/24/2016 03:07 AM, cy wrote: Then what's ctRegex in there for at all...? Optimization. ctRegex requires that the pattern is available as a compile time constant. It uses that property to "generate optimized native machine co

Re: How to avoid ctRegex (solved)

2016-08-23 Thread ag0aep6g via Digitalmars-d-learn
On 08/24/2016 03:07 AM, cy wrote: Then what's ctRegex in there for at all...? Optimization. ctRegex requires that the pattern is available as a compile time constant. It uses that property to "generate optimized native machine code". The plain regex function doesn't have such a requirement.

Re: How to avoid ctRegex (solved)

2016-08-23 Thread cy via Digitalmars-d-learn
On Tuesday, 23 August 2016 at 04:51:19 UTC, ag0aep6g wrote: That's true, and apparently `regex("foobar")` can be evaluated at compile time. Then what's ctRegex in there for at all...?

Re: How to avoid ctRegex (solved)

2016-08-22 Thread ag0aep6g via Digitalmars-d-learn
On 08/23/2016 06:06 AM, cy wrote: On Sunday, 21 August 2016 at 21:18:11 UTC, ag0aep6g wrote: I may be missing the point here, but just putting `auto pattern = regex("foobar");` at module level works for me. Really? I thought global variables could only be initialized with static stuff availab

Re: How to avoid ctRegex (solved)

2016-08-22 Thread cy via Digitalmars-d-learn
On Sunday, 21 August 2016 at 21:18:11 UTC, ag0aep6g wrote: I may be missing the point here, but just putting `auto pattern = regex("foobar");` at module level works for me. Really? I thought global variables could only be initialized with static stuff available during compile time, and you ne

Re: How to avoid ctRegex (solved)

2016-08-21 Thread ag0aep6g via Digitalmars-d-learn
On 08/21/2016 10:06 PM, cy wrote: in the module scope, you start with: auto pattern = ctRegex!"foobar"; and you substitute with: typeof(regex("")) pattern; static this() { pattern = regex("foobar"); } I may be missing the point here, but just putting `auto pattern = regex("foobar");` at mod

How to avoid ctRegex (solved)

2016-08-21 Thread cy via Digitalmars-d-learn
At seconds PER (character range) pattern, ctRegex slows down compilation like crazy, but it's not obvious how to avoid using it, since Regex(Char) is kind of weird for a type. So, here's what I do. I think this is right. in the module scope, you start with: auto pattern = ctRegex!"foobar"; an