On Thu, 22 Oct 2009 10:49:43 -0400, Jeremie Pelletier <[email protected]> wrote:
>http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/ > >Bartosz's second part of 'Template Metaprogramming Made Easy (Huh?)', >its quite a read :) template allSatisfy(alias Pred, T...) { foreach(t; T) if (!Pred!(t)) return false; return true; } Not that I disagree but something similar is doable now with CTFE + 'static' foreach hack. Of course you cannot return types, etc. template TypeTuple(A...) { alias A TypeTuple; } bool allSatisfy(alias pred, T...)() { foreach (i, _; T) { static if (!pred!(T[i])) return false; } return true; } template TypePred(T) { bool TypePred(U)() { return is(T == U); } } enum r = allSatisfy!(TypePred!bool, TypeTuple!(bool, bool, bool)); static assert(r); BTW, is Bartosz's code published anywhere and what is the license? It looks like I'm trying to do the same thing.
