Checking for possibility of implicit conversions
Alex Rønne Petersen
xtzgzorex at gmail.com
Wed Mar 14 10:07:48 PDT 2012
On 14-03-2012 18:07, H. S. Teoh wrote:
> How do I check if a given type T can be implicitly converted to some
> type S at compile-time? I'm trying to write a signature constraint for a
> template function that should only be instantiated if the parameter type
> can be implicitly assigned to some given type S.
>
> struct S(T) {
> T value;
>
> void setValue(S)(S newValue)
> if ( /* ???? */ )
> {
> value = newValue;
> }
>
> I tried __traits(compiles, value = newValue) but it seems to always
> return true, and then later the compiler errors out at the actual
> assignment statement. I'd like to be able to catch this at the signature
> constraint instead of inside the function body.
>
>
> T
>
http://dlang.org/phobos/std_traits.html#isImplicitlyConvertible
--
- Alex
More information about the Digitalmars-d-learn
mailing list