Skip to content

Commit

Permalink
Merge pull request #1244 from AndrejMitrovic/Fix7666
Browse files Browse the repository at this point in the history
Issue 7666 - Implement function to reverse fields of a tuple.
  • Loading branch information
andralex committed Apr 5, 2013
2 parents 41561d8 + cc7c5c5 commit 5c2890f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions std/typecons.d
Expand Up @@ -551,6 +551,21 @@ assert(s[0] == "abc" && s[1] == 4.5);
return *cast(typeof(return) *) &(field[from]);
}

/**
Return a copy of this Tuple with its fields in reverse order.
*/
@property
auto reversed()
{
static if (is(typeof(this) : Tuple!A, A...))
alias RevTypes = Reverse!A;

Tuple!RevTypes result;
auto tup = this.tupleof;
result.tupleof = Reverse!tup;
return result;
}

/**
The length of the tuple.
*/
Expand Down Expand Up @@ -739,6 +754,13 @@ unittest
alias Tuple!(const(int)) T;
auto t2 = T(1);
}
// 7666
{
auto tup = tuple(1, "2");
assert(tup.reversed == tuple("2", 1));
auto tup2 = tuple(1);
assert(tup2.reversed == tuple(1));
}
}
unittest
{
Expand Down

0 comments on commit 5c2890f

Please sign in to comment.