metaprogramming question

Philippe Sigaud philippe.sigaud at gmail.com
Sun Apr 18 22:58:07 PDT 2010


On Mon, Apr 19, 2010 at 07:43, Justin Spahr-Summers <
Justin.SpahrSummers at gmail.com> wrote:

>
> Yes, sorry. That's what I was trying to do originally, but I couldn't
> quite spit it out. Indeed, templating the actual arguments is a horrible
> idea.
>

Sorry to comment on it, then. I'm discovering all this by myself, so I don't
know if what I generally post is a well-known established practice or a nice
trick few people use... (or a brillant idea only a genius could utter, but
hey...)

Just to complete it, and as it's on my mind: I found one case, yesterday,
when you have to pass the args as CT args: filtering on a tuple. Strange
idea maybe, but fun to code.
That is:

auto t = tuple(1, 'a', "abc", 3.14159);
auto f = filterTuple!(polymorphicPredicate)(t); // should return a smaller
tuple, with 1, 'a',... filtered according to polymPredicate

This does not work, because I have to determine the return type of
filterTuple as CT, obviously. And this return type in turn depends on the
_values_ stored inside the tuple. At CT, I can check the types, but not the
values, unless I use them as CT args:
auto f = filterTuple!(polymorphicPredicate, t)();

But then, I'm limited by what you can use as a template parameter (not all
possible D types are allowed, I think). Maybe as an alias...

I'll stop, now, before derailing the thread. I'm trying to use tuples as a
sort-of cousin of ranges, by mapping, chaining or truncating them...

Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100419/ef9a754a/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list