[Israel.pm] [Fwd: Re: C++ Templates Zen]

Shmuel Fomberg semuelf at 012.net.il
Wed Feb 18 06:57:01 PST 2009

Shlomi Fish wrote:

>> I'm going to start learning C++ Templates Zen, for PPI's Tokenizer.
>> Wish me luck.
> But why do you need it? Isn't PPI written in Perl? Or do you mean something 
> else beside http://search.cpan.org/dist/PPI/ ?

It is, but for performance, I'm writing a C++ port for its tokenizer.

Now, enabled with template mojo, I can write things like:
		PredicateNot< PredicateFunc< is_digit > >,
		PredicateFunc< is_word > >,
		PredicateZeroOrMore< PredicateFunc< is_whitespace > >,
		PredicateFunc< is_quote > >,
		PredicateFunc< is_word > > > regex;

Which implement the regex: /^(?: (?!\d)\w | \s*['"`] | \\\w ) /x.
And I get:
1. somewhat readable.
  (probably C programmer will prefer this for regular expressions... :-)
2. no virtual functions
  (because every class knows exactly the type of its inners)
3. most of the code will be inlined
  (or so I hope)
4. I can make the whole thing static

I just hope that I won't have to convert it to C one day.
The compiler does so much work for me here, that I'd hate to do it myself.

If someone is interested in the C++ code that enable it, drop me an email.


More information about the Perl mailing list