

//
// Union?
//

Union?(x) = false;
[..T] overload Union?(static Union[..T]) = true;


//
// UnionMembers
//

[..T] UnionMembers(static Union[..T]) = ..T;



//
// constructors, resetUnsafe, destroy
//

[..T]
inline overload Union[..T]() --> returned:Union[..T] {
}

[..T,U | inValues?(U,..T)]
inline overload Union[..T](x:U) --> returned:Union[..T] {
    alias i = static valueIndex(U, ..UnionMembers(Union[..T]));
    staticIndex(returned, i) <-- x;
}



//
// staticIndex
//

[..T, i]
inline overload staticIndex(x:Union[..T], static i) {
    alias T = nthValue(static SizeT(i), ..UnionMembers(Union[..T]));
    return ref Pointer[T](&x)^;
}
