Skip to content

Commit

Permalink
Redocument and tweak adjoin
Browse files Browse the repository at this point in the history
  • Loading branch information
monarchdodra committed Mar 13, 2014
1 parent 1fa56c6 commit 13eec8d
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions std/functional.d
Expand Up @@ -348,31 +348,37 @@ Takes multiple functions and adjoins them together. The result is a
$(XREF typecons, Tuple) with one element per passed-in function. Upon
invocation, the returned tuple is the adjoined results of all
functions.
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)
{
auto adjoin(V...)(auto ref V a)
static if (F.length == 1)
{
static if (F.length == 1)
{
return F[0](a);
}
else static if (F.length == 2)
{
import std.typecons : Tuple, tuple;
return tuple(F[0](a), F[1](a));
}
else
alias adjoin = F[0];
}
else
{
auto adjoin(V...)(auto ref V a)
{
import std.typecons : Tuple, tuple;
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)
static if (F.length == 2)
{
emplaceRef(result[i], F[i](a));
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)
{
emplaceRef(result[i], F[i](a));
}
return result;
}
return result;
}
}
}
Expand Down

0 comments on commit 13eec8d

Please sign in to comment.