mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 13:40:20 +03:00
commit
e67d040bc9
1 changed files with 11 additions and 47 deletions
58
std/meta.d
58
std/meta.d
|
@ -511,30 +511,19 @@ if (args.length >= 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an `AliasSeq` created from TList with all occurrences
|
* Returns an `AliasSeq` created from `args[2 .. $]` with all occurrences
|
||||||
* of T, if found, replaced with U.
|
* of `args[0]`, if any, replaced with `args[1]`.
|
||||||
*/
|
*/
|
||||||
template ReplaceAll(T, U, TList...)
|
template ReplaceAll(args...)
|
||||||
{
|
{
|
||||||
alias ReplaceAll = GenericReplaceAll!(T, U, TList).result;
|
alias ReplaceAll = AliasSeq!();
|
||||||
}
|
static foreach (arg; args[2 .. $])
|
||||||
|
{
|
||||||
/// Ditto
|
static if (isSame!(args[0], arg))
|
||||||
template ReplaceAll(alias T, U, TList...)
|
ReplaceAll = AliasSeq!(ReplaceAll, args[1]);
|
||||||
{
|
else
|
||||||
alias ReplaceAll = GenericReplaceAll!(T, U, TList).result;
|
ReplaceAll = AliasSeq!(ReplaceAll, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ditto
|
|
||||||
template ReplaceAll(T, alias U, TList...)
|
|
||||||
{
|
|
||||||
alias ReplaceAll = GenericReplaceAll!(T, U, TList).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ditto
|
|
||||||
template ReplaceAll(alias T, alias U, TList...)
|
|
||||||
{
|
|
||||||
alias ReplaceAll = GenericReplaceAll!(T, U, TList).result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -546,31 +535,6 @@ template ReplaceAll(alias T, alias U, TList...)
|
||||||
static assert(is(TL == AliasSeq!(int, char, char, int, float)));
|
static assert(is(TL == AliasSeq!(int, char, char, int, float)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// [internal]
|
|
||||||
private template GenericReplaceAll(args...)
|
|
||||||
if (args.length >= 2)
|
|
||||||
{
|
|
||||||
alias from = OldAlias!(args[0]);
|
|
||||||
alias to = OldAlias!(args[1]);
|
|
||||||
alias tuple = args[2 .. $];
|
|
||||||
|
|
||||||
static if (tuple.length)
|
|
||||||
{
|
|
||||||
alias head = OldAlias!(tuple[0]);
|
|
||||||
alias tail = tuple[1 .. $];
|
|
||||||
alias next = GenericReplaceAll!(from, to, tail).result;
|
|
||||||
|
|
||||||
static if (isSame!(from, head))
|
|
||||||
alias result = AliasSeq!(to, next);
|
|
||||||
else
|
|
||||||
alias result = AliasSeq!(head, next);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
alias result = AliasSeq!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
static assert(Pack!(ReplaceAll!(byte, ubyte,
|
static assert(Pack!(ReplaceAll!(byte, ubyte,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue