digitalmars.D.learn - ImplicitConversionTargets opposite
- Freddy (3/3) May 21 2015 std.traits has ImplicitConversionTargets.
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (5/8) May 22 2015 I doubt that, because it's an open set (alias this, inheritance).
- Baz (30/33) May 22 2015 You can write something like this:
- Baz (1/1) May 22 2015 the line warping on this forum deserve a big slap in the face...
std.traits has ImplicitConversionTargets. Is there any template that returns the types that can implicty convert to T?
May 21 2015
On Thursday, 21 May 2015 at 21:49:55 UTC, Freddy wrote:std.traits has ImplicitConversionTargets. Is there any template that returns the types that can implicty convert to T?I doubt that, because it's an open set (alias this, inheritance). However, it should be possible to iterate over all types in a given module, and select only those that are implicitly convertible to your type.
May 22 2015
On Thursday, 21 May 2015 at 21:49:55 UTC, Freddy wrote:std.traits has ImplicitConversionTargets. Is there any template that returns the types that can implicty convert to T?You can write something like this: --- import std.stdio; import std.traits; import std.typetuple; void main(string[] args) { template PossibleType(From) { private alias All = TypeTuple!(byte,ubyte,short,ushort,int,uint); private alias Convertible(To) = isImplicitlyConvertible!(From,To); public alias PossibleType = Filter!(Convertible, All); } writeln((PossibleType!int).stringof); writeln((PossibleType!short).stringof); } --- which outputs: --- (int, uint) (short, ushort, int, uint) --- The idea is to reduce the list of all the possible types. It's easy because the high-order functional functions are implemented for the type list. `All` could be a template parameter, and more filled, but to keep the example simple here it's not.
May 22 2015
the line warping on this forum deserve a big slap in the face...
May 22 2015