"is" expression and type tuples
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 4 00:47:49 PST 2015
Jack Applegame:
> On Tuesday, 3 March 2015 at 17:49:24 UTC, bearophile wrote:
>> That's 1 + n-1 :-)
> Could you please explain what does '1 + n-1' mean?
This is your code:
>> template Is(ARGS...) if(ARGS.length % 2 == 0) {
>> enum N = ARGS.length/2;
>> static if(N == 1) enum Is = is(ARGS[0] : ARGS[1]);
>> else enum Is = is(ARGS[0] : ARGS[N]) && Is!(ARGS[1..N],
>> ARGS[N+1..$]);
>> }
The recursion scheme you are using is working on a single item (a
single pair of items), and then calling the recursion on all
other items but the first.
If you look in std.traits you see examples of a different
recursion that reduces compilation time:
template isExpressionTuple(T ...)
{
static if (T.length >= 2)
enum bool isExpressionTuple =
isExpressionTuple!(T[0 .. $/2]) &&
isExpressionTuple!(T[$/2 .. $]);
else static if (T.length == 1)
enum bool isExpressionTuple =
!is(T[0]) && __traits(compiles, { auto ex = T[0]; });
else
enum bool isExpressionTuple = true; // default
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list