template const to compile-time function

Carlos Santander csantander619 at gmail.com
Tue Sep 4 14:59:18 PDT 2007


Daniel Keep escribió:
> 
> string seqWrapper(string property, string seq, string array)
> {
>     return `typeof(`~array~`) `~property~`()
>     {
>         if( (`~array~`).length == 0 )
>             `~array~` = seqToArray(`~seq~`);
>         return `~array~`;
>     }`;
> }
> 
> mixin (seqWrapper("users","_list","_users"));
> 

I hadn't thought of that first line with typeof. Thanks.

> Six of one, half-dozen of the other, really.  Unless you need to do
> stuff involving loops or string processing, templates are quite sufficient.
> 
> 	-- Daniel

I was thinking about code-generation bloat, but I guess I'd have to measure that 
myself.

-- 
Carlos Santander Bernal


More information about the Digitalmars-d-learn mailing list