"extern" template instantiation

Dmitry Olshansky dmitry.olsh at gmail.com
Thu Oct 24 09:36:50 PDT 2013


24-Oct-2013 20:30, Mathias LANG пишет:
> 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 ?
>

Something to the extent of

auto getMeARegex()
{
	static 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]+)$"); 

	return r;
}

_Might_ work. Failing that make it an 0-arg template:
auto getMeARegex()(){ ... }

> 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.


-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list