"extern" template instantiation

Mathias LANG pro.mathias.lang at gmail.com
Thu Oct 24 09:30:09 PDT 2013


On Wednesday, 23 October 2013 at 11:58:17 UTC, Dicebot wrote:
> Using `enum` with ctRegex is discouraged because it is a dumb 
> copy-paste upon every enum usage. I'd recommend to use global 
> variable initialized during compile-time:
>
> ```
> auto r = 
> ctRegex!(r"^(\w+)\s+([a-zA-Z0-9/]+)\?a=(\w+)&b=(\w+)&c=(\w+)([&\D+=\w+)]*)&y=([0-9A-Fa-z]+)&z=([0-9A-Fa-z]+)$");
> ```
>
> Though it is pretty complex ctRegex and compiling it is a good 
> stress test for any compiler :)

Using auto was my first try. Unfortunately it has the same issue 
(slighly faster, but still "dumb C/P". So far I didn't find any 
way to tell the compiler not to compile it if I'm not using it 
(aside from versions).
As the type itself takes ages to compile, any reasonable-sized 
project with few regexes will not be able to use ctRegex in dev 
mode. I suppose there's no way to create a function that returns 
a generic ctRegex object without loosing the advantages ?

Note: The regex might seems complex, but actually isn't.
It parses an home-made REST API  based on query authentification: 
http://broadcast.oreilly.com/2009/12/principles-for-standardized-rest-authentication.html 
. To me it sounded like a simple use case.


More information about the Digitalmars-d-learn mailing list