Skip to content

Commit

Permalink
Merge pull request #5401 from andralex/enum-representation
Browse files Browse the repository at this point in the history
Add asOriginalType function for enums
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
  • Loading branch information
dlang-bot committed May 19, 2017
2 parents a45dc66 + bf43110 commit 46a3cda
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -4235,6 +4235,27 @@ private bool isOctalLiteral(const string num)
assert(b == 1);
}

// asOriginalType
/**
Returns the representation of an enumerated value, i.e. the value converted to
the base type of the enumeration.
*/
OriginalType!E asOriginalType(E)(E value) if (is(E == enum))
{
return value;
}

///
unittest
{
enum A { a = 42 }
static assert(is(typeof(A.a.asOriginalType) == int));
assert(A.a.asOriginalType == 42);
enum B : double { a = 43 }
static assert(is(typeof(B.a.asOriginalType) == double));
assert(B.a.asOriginalType == 43);
}

/+
emplaceRef is a package function for phobos internal use. It works like
emplace, but takes its argument by ref (as opposed to "by pointer").
Expand Down

0 comments on commit 46a3cda

Please sign in to comment.