metaprograming: staticMap and such?

Dmitry Olshansky dmitry.olsh at gmail.com
Tue Jul 6 13:22:19 PDT 2010


Hello there!

Got my TDPL some week ago, being playing with D for a while.
Excited with results I'm porting my personal C++ codebase now.
So far everything was kinda cool - even better (not to mention huge code 
savings).

Now I'm messing with metaprograming. Simple task at hand:  given 
typetuple of types produce typetuple of arrays of corresponding types.
Built in typetuples - great, but here's where some usual (boost 
MPL-like) library stuff has gone missing.

First, StaticMap described in phobos docs simply not exists in 
typetuple.d (using dmd 2.047), here is my drop-in replacement:

template staticMap(alias F,T...){
     static if(T.length > 1){
         alias TypeTuple!(F!(T[0]),staticMap!(F,T[1..$])) staticMap;
     }else{
         alias TypeTuple!(F!(T[0])) staticMap;
     }
}

Yes, and also having some simple meta-functors packaged along couldn't 
hurt. Something like :
template addArray(T){ alias T[] addArray;  }

So the question boils down to: what are you guys using std.typetuple for 
metaprograming and what's it's status?

---
Dmitry Olshansky


More information about the Digitalmars-d mailing list