@@ -175,9 +175,6 @@ alias AliasSeq(TList...) = TList;
175175 */
176176alias Alias (alias a) = a;
177177
178- // / Ditto
179- alias Alias (T) = T;
180-
181178// /
182179@safe unittest
183180{
@@ -222,32 +219,6 @@ alias Alias(T) = T;
222219 assert (g == 7 );
223220}
224221
225- package template OldAlias(alias a)
226- {
227- static if (__traits(compiles, { alias x = a; }))
228- alias OldAlias = a;
229- else static if (__traits(compiles, { enum x = a; }))
230- enum OldAlias = a;
231- else
232- static assert (0 , " Cannot alias " ~ a.stringof);
233- }
234-
235- package template OldAlias(T)
236- if (! isAggregateType! T || is (Unqual! T == T))
237- {
238- alias OldAlias = T;
239- }
240-
241- @safe unittest
242- {
243- static struct Foo {}
244- // static assert(is(OldAlias!(const(Foo)) == const Foo));
245- static assert (is (OldAlias! (const (int )) == const (int )));
246- static assert (OldAlias! 123 == 123 );
247- enum abc = 123 ;
248- static assert (OldAlias! abc == 123 );
249- }
250-
251222/**
252223 * Returns the index of the first occurrence of `args[0]` in the
253224 * sequence `args[1 .. $]`. `args` may be types or compile-time values.
@@ -431,30 +402,26 @@ template NoDuplicates(args...)
431402
432403
433404/**
434- * Returns an `AliasSeq` created from TList with the first occurrence
405+ * Returns an `AliasSeq` created from Seq with the first occurrence
435406 * of T, if found, replaced with U.
436407 */
437- template Replace (T, U, TList... )
438- {
439- alias Replace = GenericReplace! (T, U, TList).result;
440- }
441-
442- // / Ditto
443- template Replace (alias T, U, TList... )
408+ template Replace (alias T, alias U, Seq... )
444409{
445- alias Replace = GenericReplace! (T, U, TList).result;
446- }
447-
448- // / Ditto
449- template Replace (T, alias U, TList... )
450- {
451- alias Replace = GenericReplace! (T, U, TList).result;
452- }
410+ static if (Seq.length)
411+ {
412+ alias head = Seq[0 .. 1 ];
413+ alias tail = Seq[1 .. $];
453414
454- // / Ditto
455- template Replace (alias T, alias U, TList... )
456- {
457- alias Replace = GenericReplace! (T, U, TList).result;
415+ static if (isSame! (T, head))
416+ alias Replace = AliasSeq! (U, tail);
417+ else
418+ alias Replace = AliasSeq! (head,
419+ Replace! (T, U, tail));
420+ }
421+ else
422+ {
423+ alias Replace = AliasSeq! ();
424+ }
458425}
459426
460427// /
@@ -466,31 +433,6 @@ template Replace(alias T, alias U, TList...)
466433 static assert (is (TL == AliasSeq! (int , char , long , int , float )));
467434}
468435
469- // [internal]
470- private template GenericReplace (args... )
471- if (args.length >= 2 )
472- {
473- alias from = OldAlias! (args[0 ]);
474- alias to = OldAlias! (args[1 ]);
475- alias tuple = args[2 .. $];
476-
477- static if (tuple.length)
478- {
479- alias head = OldAlias! (tuple[0 ]);
480- alias tail = tuple[1 .. $];
481-
482- static if (isSame! (from, head))
483- alias result = AliasSeq! (to, tail);
484- else
485- alias result = AliasSeq! (head,
486- GenericReplace! (from, to, tail).result);
487- }
488- else
489- {
490- alias result = AliasSeq! ();
491- }
492- }
493-
494436@safe unittest
495437{
496438 static assert (Pack! (Replace! (byte , ubyte ,
@@ -511,16 +453,16 @@ if (args.length >= 2)
511453}
512454
513455/**
514- * Returns an `AliasSeq` created from ` args[2 .. $]` with all occurrences
515- * of `args[0]` , if any , replaced with `args[1]` .
456+ * Returns an `AliasSeq` created from args with all occurrences
457+ * of T , if found , replaced with U .
516458 */
517- template ReplaceAll (args... )
459+ template ReplaceAll (alias T, alias U, args... )
518460{
519461 alias ReplaceAll = AliasSeq! ();
520- static foreach (arg; args[ 2 .. $] )
462+ static foreach (arg; args)
521463 {
522- static if (isSame! (args[ 0 ] , arg))
523- ReplaceAll = AliasSeq! (ReplaceAll, args[ 1 ] );
464+ static if (isSame! (T , arg))
465+ ReplaceAll = AliasSeq! (ReplaceAll, U );
524466 else
525467 ReplaceAll = AliasSeq! (ReplaceAll, arg);
526468 }
@@ -1297,10 +1239,9 @@ private template staticMerge(alias cmp, uint mid, items...)
12971239 staticMerge! (cmp, mid - run, items[run .. mid], items[mid + 1 .. $]));
12981240}
12991241
1300- private template isLessEq (alias cmp, Seq... )
1301- if (Seq.length == 2 )
1242+ private template isLessEq (alias cmp, alias A, alias B)
13021243{
1303- private enum Result = cmp! (Seq[ 1 ], Seq[ 0 ] );
1244+ private enum Result = cmp! (B, A );
13041245 static if (is (typeof (Result) == bool ))
13051246 enum isLessEq = ! Result;
13061247 else static if (is (typeof (Result) : int ))
@@ -1452,11 +1393,6 @@ private template isSame(alias a, alias b)
14521393 enum isSame = __traits(isSame, a, b);
14531394 }
14541395}
1455- // TODO: remove after https://github.com/dlang/dmd/pull/11320 and https://issues.dlang.org/show_bug.cgi?id=21889 are fixed
1456- private template isSame (A, B)
1457- {
1458- enum isSame = is (A == B);
1459- }
14601396
14611397@safe unittest
14621398{
0 commit comments