vibe.internal.meta.typetuple 0/4(0%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
/** Additions to std.typetuple pending for inclusion into Phobos. Copyright: © 2013 RejectedSoftware e.K. License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. Authors: Михаил Страшун */ module vibe.internal.meta.typetuple; import std.typetuple; import std.traits; /** TypeTuple which does not auto-expand. Useful when you need to multiple several type tuples as different template argument list parameters, without merging those. */ template Group(T...) { alias expand = T; } /// unittest { alias group = Group!(int, double, string); static assert (!is(typeof(group.length))); static assert (group.expand.length == 3); static assert (is(group.expand[1] == double)); } /** */ template isGroup(T...) { static if (T.length != 1) enum isGroup = false; else enum isGroup = !is(T[0]) && is(typeof(T[0]) == void) // does not evaluate to something && is(typeof(T[0].expand.length) : size_t) // expands to something with length && !is(typeof(&(T[0].expand))); // expands to not addressable } version (unittest) // NOTE: GDC complains about template definitions in unittest blocks { alias group = Group!(int, double, string); alias group2 = Group!(); template Fake(T...) { int[] expand; } alias fake = Fake!(int, double, string); alias fake2 = TypeTuple!(int, double, string); static assert (isGroup!group); static assert (isGroup!group2); static assert (!isGroup!fake); static assert (!isGroup!fake2); } /* Copied from Phobos as it is private there. */ private template isSame(ab...) if (ab.length == 2) { static if (is(ab[0]) && is(ab[1])) { enum isSame = is(ab[0] == ab[1]); } else static if (!is(ab[0]) && !is(ab[1]) && is(typeof(ab[0] == ab[1]) == bool) && (ab[0] == ab[1])) { static if (!__traits(compiles, &ab[0]) || !__traits(compiles, &ab[1])) enum isSame = (ab[0] == ab[1]); else enum isSame = __traits(isSame, ab[0], ab[1]); } else { enum isSame = __traits(isSame, ab[0], ab[1]); } } /** Compares two groups for element identity Params: Group1, Group2 = any instances of `Group` Returns: `true` if each element of Group1 is identical to the one of Group2 at the same index */ template Compare(alias Group1, alias Group2) if (isGroup!Group1 && isGroup!Group2) { private template implementation(size_t index) { static if (Group1.expand.length != Group2.expand.length) enum implementation = false; else static if (index >= Group1.expand.length) enum implementation = true; else static if (!isSame!(Group1.expand[index], Group2.expand[index])) enum implementation = false; else enum implementation = implementation!(index+1); } enum Compare = implementation!0; } /// unittest { alias one = Group!(int, double); alias two = Group!(int, double); alias three = Group!(double, int); static assert (Compare!(one, two)); static assert (!Compare!(one, three)); }