Skip to content

Commit

Permalink
Split adjoin in two templates
Browse files Browse the repository at this point in the history
  • Loading branch information
monarchdodra committed Mar 15, 2014
1 parent a41c349 commit a965d76
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions std/functional.d
Expand Up @@ -353,32 +353,30 @@ Note: In the special case where where only a single function is provided
($(D F.length == 1)), adjoin simply aliases to the single passed function
($(D F[0])).
*/
template adjoin(F...) if (F.length)
template adjoin(F...) if (F.length == 1)
{
static if (F.length == 1)
{
alias adjoin = F[0];
}
else
alias adjoin = F[0];
}
/// ditto
template adjoin(F...) if (F.length > 1)
{
auto adjoin(V...)(auto ref V a)
{
auto adjoin(V...)(auto ref V a)
import std.typecons : Tuple, tuple;
static if (F.length == 2)
{
import std.typecons : Tuple, tuple;
static if (F.length == 2)
{
return tuple(F[0](a), F[1](a));
}
else
return tuple(F[0](a), F[1](a));
}
else
{
import std.conv : emplaceRef;
alias Head = typeof(F[0](a));
Tuple!(Head, typeof(.adjoin!(F[1..$])(a)).Types) result = void;
foreach (i, Unused; result.Types)
{
import std.conv : emplaceRef;
alias Head = typeof(F[0](a));
Tuple!(Head, typeof(.adjoin!(F[1..$])(a)).Types) result = void;
foreach (i, Unused; result.Types)
{
emplaceRef(result[i], F[i](a));
}
return result;
emplaceRef(result[i], F[i](a));
}
return result;
}
}
}
Expand Down

0 comments on commit a965d76

Please sign in to comment.