Using allSatisfy with template that takes multiple type arguments
Philippe Sigaud
philippe.sigaud at gmail.com
Mon Sep 26 12:49:57 PDT 2011
On Mon, Sep 26, 2011 at 21:40, Andrej Mitrovic
<andrej.mitrovich at gmail.com> wrote:
> Actually now that I think about it, isOneOf!() is more to my liking.
> isImplicitlyConvertible allows too much, e.g. implicit casting of
> unsigned to signed. Even though that might be perfectly valid, I want
> to optionally allow a warning via a version switch. So I'll be using
> isOneOf.
In any case, concerning your initial question, a possibility is to
curry the template:
template isCompatible(T)
{
enum isCompatible = allSatisfy!(isIC!T, MyTypes);
}
template isIC(First)
{
template isIC(Second)
{
enum isIC = isImplicitlyConvertible!(First, Second);
}
}
So, isIC!T yields *another* template (also named isIC), that will
accept one type and be mapped on MyTypes by allSatisfy. What's cool is
that the second-level template remembers First. It's a bit like a
closure, but on types.
More information about the Digitalmars-d-learn
mailing list