DIP66 - Multiple alias this

IgorStepanov via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 28 15:55:23 PDT 2014


On Tuesday, 28 October 2014 at 21:55:35 UTC, Meta wrote:
> On Tuesday, 28 October 2014 at 20:09:07 UTC, IgorStepanov wrote:
>> And please comment my way to resolving "is" expression via 
>> alias-this:
>> http://forum.dlang.org/thread/ubafmwvxwtolhmnxbrsf@forum.dlang.org?page=5
>
> Something else related to the discussion about `is` from this 
> thread: 
> http://forum.dlang.org/post/tulvmydnogbgebnxybfk@forum.dlang.org. 
> The following code:
>
> import std.math;
> import std.traits;
>
> struct S(T)
> if(isFloatingPoint!T)
> {
>     T val;
>     alias val this;
> }
>
> void main()
> {
>
>     auto s = S!float();
>     assert(isNaN(s));
>     s = 10.0;
>     assert(!isNaN(s));
> }
>
> Current fails to compile with this error:
>
> Error: template std.math.isNaN cannot deduce function from
> argument types !()(S!float), candidates are:
>
> std/math.d(4171):        std.math.isNaN(X)(X x) if
> (isFloatingPoint!X)
>
> Is this a problem with the current implementation of `alias 
> this`, or should isFloatingPoint be changed so that it also 
> accepts types that alias a floating point type?

You may see isFloatingPoint declaration in traits.d:
enum bool isFloatingPoint(T) = is(FloatingPointTypeOf!T) && 
!isAggregateType!T;

This template explicitly says that T shouldn't be an aggregate 
type. Thus
std.math.isNaN(X)(X x) if (isFloatingPoint!X)
shouldn't accept a struct.


More information about the Digitalmars-d mailing list