<div class="gmail_quote">Hi Dmitry,<br><br>On Tue, Jul 6, 2010 at 22:22, Dmitry Olshansky <span dir="ltr"><<a href="mailto:dmitry.olsh@gmail.com">dmitry.olsh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello there!<br>
<br>
Got my TDPL some week ago, being playing with D for a while.<br>
Excited with results I'm porting my personal C++ codebase now.<br>
So far everything was kinda cool - even better (not to mention huge code savings).<br>
<br>
Now I'm messing with metaprograming. Simple task at hand: given typetuple of types produce typetuple of arrays of corresponding types.<br>
Built in typetuples - great, but here's where some usual (boost MPL-like) library stuff has gone missing.<br>
<br>
First, StaticMap described in phobos docs simply not exists in typetuple.d (using dmd 2.047), here is my drop-in replacement:<br>
<br>
template staticMap(alias F,T...){<br>
static if(T.length > 1){<br>
alias TypeTuple!(F!(T[0]),staticMap!(F,T[1..$])) staticMap;<br>
}else{<br>
alias TypeTuple!(F!(T[0])) staticMap;<br>
}<br>
}<br>
<br></blockquote><div><br>It's in std.typetuple, but it's called staticMap with a small 's'. I agree it should be called StaticMap (big S), as it becomes a type.<br><br>I think you should have a case for T.length == 0. One can map the empty typetuple, after all, particularly if this tuple is the result of another template and can be void in some circumstances. <br>
Ah, I see bearophile also said this. Hmm, same time zone, Leonardo :-)<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Yes, and also having some simple meta-functors packaged along couldn't hurt. Something like :<br>
template addArray(T){ alias T[] addArray; }<br></blockquote><div><br>And isn't that cool that meta-programming (or rather, type manipulation) is so simple in D?<br><br>alias TypeTuple!(int, double, string) Types;<br>
alias StaticMap!(addArray, Types) ArrayTypes; // ArrayTypes is TypeTuple!(int[], double[], string[]) <br></div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
So the question boils down to: what are you guys using std.typetuple for metaprograming and what's it's status?<font color="#888888"><br></font></blockquote><div><br>I'm using it a lot, mainly for two reasons:<br>
<br>- 'auto' is still buggy: auto function do not show in documentation comments and (worse) type deduction through many invocation of 'auto' do not work, due to forward reference limitation. So I tried to get rid of auto as much as I could in my code base. It made me code a whole machinery for type manipulation, to get the correct return types for deeply nested functions. Templates, meta-templates(!), etc. I gather I'll get rid of them when the auto propagation will see its bugs squashed.<br>
<br>- for fun, to construct and encode things in types :-) Peano numbers, trees, etc.<br></div></div><br><br>As for its status, I consider it a pretty solid part of Phobos, if somewhat obscure. No bugs I know of (well, except the _s/S_taticMap calling convention), a good example of type manipulation in D. It gave me lots of ideas.<br>
<br>I had some fun with this (filtering, folding, takeWhile, ...), here is the result:<br><br><a href="http://svn.dsource.org/projects/dranges/trunk/dranges/docs/typetuple2.html">http://svn.dsource.org/projects/dranges/trunk/dranges/docs/typetuple2.html</a><br>
<br>Uh oh, this page is looking for some documentation. All the fun new templates I put there are not correctly documented. I will do that.<br><br><br>Philippe<br>