digitalmars.D.learn - "is" expression and type tuples
- Jack Applegame (2/6) Mar 03 2015 Is it by design, or just not implemented?
- bearophile (7/14) Mar 03 2015 It's by design, perhaps because Walter didn't think of this case,
- Jack Applegame (2/13) Mar 03 2015
- bearophile (4/15) Mar 03 2015 That's 1 + n-1 :-)
- Jack Applegame (2/3) Mar 03 2015 Could you please explain what does '1 + n-1' mean?
- bearophile (21/30) Mar 04 2015 The recursion scheme you are using is working on a single item (a
Seems like "is" expression doesn't support type tuples:pragma(msg, is(short : int)); // true enum Test(ARGS...) = is(ARGS[0..2] : ARGS[2..4]); pragma(msg, is(Test!(int, int, int, int))); // false pragma(msg, Test!(int, short, int, int)); // falseIs it by design, or just not implemented?
Mar 03 2015
Jack Applegame:Seems like "is" expression doesn't support type tuples:It's by design, perhaps because Walter didn't think of this case, or probably for compiler simplicity. But it should be not too much hard to implement it your code. Just use two is(), or use recursion (with splitting in two, and not 1 + n-1). Bye, bearophilepragma(msg, is(short : int)); // true enum Test(ARGS...) = is(ARGS[0..2] : ARGS[2..4]); pragma(msg, is(Test!(int, int, int, int))); // false pragma(msg, Test!(int, short, int, int)); // falseIs it by design, or just not implemented?
Mar 03 2015
On Tuesday, 3 March 2015 at 16:42:22 UTC, bearophile wrote:But it should be not too much hard to implement it your code. Just use two is(), or use recursion (with splitting in two, and not 1 + n-1). Bye, bearophileI already have one: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..$]); }
Mar 03 2015
Jack Applegame:That's 1 + n-1 :-) Bye, bearophileor use recursion (with splitting in two, and not 1 + n-1). Bye, bearophileI already have one: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..$]); }
Mar 03 2015
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?
Mar 03 2015
Jack Applegame:On Tuesday, 3 March 2015 at 17:49:24 UTC, bearophile wrote:This is your code:That's 1 + n-1 :-)Could you please explain what does '1 + n-1' mean?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, bearophiletemplate 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..$]); }
Mar 04 2015