TypeFunction example creatiing a conversion matrix
Stefan Koch
uplink.coder at gmail.com
Thu Oct 1 19:37:43 UTC 2020
On Thursday, 1 October 2020 at 19:33:09 UTC, Andrei Alexandrescu
wrote:
>
> A proof of concept would be helpful.
You mean this one:
template ImplicitConversionTargets(T)
{
static if (is(T == bool))
alias ImplicitConversionTargets =
AliasSeq!(byte, ubyte, short, ushort, int, uint,
long, ulong, CentTypeList,
float, double, real, char, wchar, dchar);
else static if (is(T == byte))
alias ImplicitConversionTargets =
AliasSeq!(short, ushort, int, uint, long, ulong,
CentTypeList,
float, double, real, char, wchar, dchar);
else static if (is(T == ubyte))
alias ImplicitConversionTargets =
AliasSeq!(short, ushort, int, uint, long, ulong,
CentTypeList,
float, double, real, char, wchar, dchar);
else static if (is(T == short))
alias ImplicitConversionTargets =
AliasSeq!(int, uint, long, ulong, CentTypeList,
float, double, real);
else static if (is(T == ushort))
alias ImplicitConversionTargets =
AliasSeq!(int, uint, long, ulong, CentTypeList,
float, double, real);
else static if (is(T == int))
alias ImplicitConversionTargets =
AliasSeq!(long, ulong, CentTypeList, float, double,
real);
else static if (is(T == uint))
alias ImplicitConversionTargets =
AliasSeq!(long, ulong, CentTypeList, float, double,
real);
else static if (is(T == long))
alias ImplicitConversionTargets = AliasSeq!(float,
double, real);
else static if (is(T == ulong))
alias ImplicitConversionTargets = AliasSeq!(float,
double, real);
else static if (is(cent) && is(T == cent))
alias ImplicitConversionTargets = AliasSeq!(float,
double, real);
else static if (is(ucent) && is(T == ucent))
alias ImplicitConversionTargets = AliasSeq!(float,
double, real);
else static if (is(T == float))
alias ImplicitConversionTargets = AliasSeq!(double, real);
else static if (is(T == double))
alias ImplicitConversionTargets = AliasSeq!real;
else static if (is(T == char))
alias ImplicitConversionTargets =
AliasSeq!(wchar, dchar, byte, ubyte, short, ushort,
int, uint, long, ulong, CentTypeList,
float, double, real);
else static if (is(T == wchar))
alias ImplicitConversionTargets =
AliasSeq!(dchar, short, ushort, int, uint, long,
ulong, CentTypeList,
float, double, real);
else static if (is(T == dchar))
alias ImplicitConversionTargets =
AliasSeq!(int, uint, long, ulong, CentTypeList,
float, double, real);
else static if (is(T : typeof(null)))
alias ImplicitConversionTargets = AliasSeq!(typeof(null));
else static if (is(T == class))
alias ImplicitConversionTargets =
staticMap!(ApplyLeft!(CopyConstness, T),
TransitiveBaseTypeTuple!(T));
else static if (isDynamicArray!T && !is(typeof(T.init[0]) ==
const))
{
static if (is(typeof(T.init[0]) == shared))
alias ImplicitConversionTargets =
AliasSeq!(const(shared(Unqual!(typeof(T.init[0]))))[]);
else
alias ImplicitConversionTargets =
AliasSeq!(const(Unqual!(typeof(T.init[0])))[]);
}
else static if (is(T : void*))
alias ImplicitConversionTargets = AliasSeq!(void*);
else
alias ImplicitConversionTargets = AliasSeq!();
}
@Andrei could you explain the semantics in detail?
The source code is somewhat obtuse.
More information about the Digitalmars-d
mailing list