Disable TypeOf on frontent versions < 2.072.x

This commit is contained in:
Sönke Ludwig 2018-01-18 00:06:06 +01:00
parent f6e90bb0c9
commit f9c7d444e6

View file

@ -658,34 +658,35 @@ unittest {
}
/** Maps a kind enumeration value to the corresponding field type.
static if (__VERSION__ >= 2072) {
/** Maps a kind enumeration value to the corresponding field type.
`kind` must be a value of the `TaggedAlgebraic!T.Kind` enumeration.
*/
template TypeOf(alias kind)
if (isInstanceOf!(TypeEnum, typeof(kind)))
{
import std.traits : FieldTypeTuple, TemplateArgsOf;
alias U = TemplateArgsOf!(typeof(kind));
alias TypeOf = FieldTypeTuple!U[kind];
}
///
unittest {
static struct S {
int a;
string b;
string c;
`kind` must be a value of the `TaggedAlgebraic!T.Kind` enumeration.
*/
template TypeOf(alias kind)
if (isInstanceOf!(TypeEnum, typeof(kind)))
{
import std.traits : FieldTypeTuple, TemplateArgsOf;
alias U = TemplateArgsOf!(typeof(kind));
alias TypeOf = FieldTypeTuple!U[kind];
}
alias TA = TaggedAlgebraic!S;
static assert(is(TypeOf!(TA.Kind.a) == int));
static assert(is(TypeOf!(TA.Kind.b) == string));
static assert(is(TypeOf!(TA.Kind.c) == string));
///
unittest {
static struct S {
int a;
string b;
string c;
}
alias TA = TaggedAlgebraic!S;
static assert(is(TypeOf!(TA.Kind.a) == int));
static assert(is(TypeOf!(TA.Kind.b) == string));
static assert(is(TypeOf!(TA.Kind.c) == string));
}
}
/** Gets the value stored in an algebraic type based on its data type.
*/
ref inout(T) get(T, U)(ref inout(TaggedAlgebraic!U) ta)