View source code
Display the source code in std/traits.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Alias std.traits.ImplicitConversionTargets

alias ImplicitConversionTargets(T) = AliasSeq!(byte,ubyte,short,ushort,int,uint,long,ulong,CentTypeList,float,double,real,char,wchar,dchar);

Parameters

NameDescription
T The type to check

Returns

An AliasSeq with all possible target types of an implicit conversion T.

If T is a class derived from Object, the the result of TransitiveBaseTypeTuple is returned.

If the type is not a built-in value type or a class derived from Object, the an empty AliasSeq is returned.

Note

The possible targets are computed more conservatively than the language allows, eliminating all dangerous conversions. For example, ImplicitConversionTargets!double does not include float.

See Also

isImplicitlyConvertible

Example

import std.meta : AliasSeq;

static assert(is(ImplicitConversionTargets!(ulong) == AliasSeq!(float, double, real)));
static assert(is(ImplicitConversionTargets!(int) == AliasSeq!(long, ulong, float, double, real)));
static assert(is(ImplicitConversionTargets!(float) == AliasSeq!(double, real)));
static assert(is(ImplicitConversionTargets!(double) == AliasSeq!(real)));

static assert(is(ImplicitConversionTargets!(char) == AliasSeq!(
    wchar, dchar, byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real
)));
static assert(is(ImplicitConversionTargets!(wchar) == AliasSeq!(
    dchar, short, ushort, int, uint, long, ulong, float, double, real
)));
static assert(is(ImplicitConversionTargets!(dchar) == AliasSeq!(
    int, uint, long, ulong, float, double, real
)));

static assert(is(ImplicitConversionTargets!(string) == AliasSeq!(const(char)[])));
static assert(is(ImplicitConversionTargets!(void*) == AliasSeq!(void*)));

interface A {}
interface B {}
class C : A, B {}

static assert(is(ImplicitConversionTargets!(C) == AliasSeq!(Object, A, B)));
static assert(is(ImplicitConversionTargets!(const C) == AliasSeq!(const Object, const A, const B)));
static assert(is(ImplicitConversionTargets!(immutable C) == AliasSeq!(
    immutable Object, immutable A, immutable B
)));

Authors

Walter Bright, Tomasz Stachowiak (isExpressions), Andrei Alexandrescu, Shin Fujishiro, Robert Clipsham, David Nadlinger, Kenji Hara, Shoichi Kato

License

Boost License 1.0.