Getting started - D meta-program question

Daniel Keep daniel.keep.lists at gmail.com
Sat Oct 3 21:04:35 PDT 2009


Justin Johansson wrote:
> There was mention** on the general discussion group that the D foreach_reverse
> language construct could be replaced (emulated?) with a (D) meta-program.
> 
> ** "Even a novice programmer can write a meta-program to replace
> foreach_reverse without any runtime performance hit."
> 
>    http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=97362
>   
> As I'm less than a novice with the D meta-programming facilities (at this stage of my journey into D),
> if someone would kindly show me the D meta-program solution to do this,
> I'd really appreciate the enlightenment.
> 
> Thanks again.

Short answer: you can't.

Long answer: you can, provided you aren't trying to reverse an opApply,
which is patently impossible.

As for the "meta-program", I would suspect whoever said that was talking
about writing a templated type or function to handle it.  You would need
to use template specialisation or static ifs to switch on what type
you've been given to reverse.

http://digitalmars.com/d/1.0/template.html

http://digitalmars.com/d/1.0/version.html#staticif


More information about the Digitalmars-d-learn mailing list