DIP66 - Multiple alias this

IgorStepanov via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 29 14:46:53 PDT 2014


On Tuesday, 28 October 2014 at 23:12:21 UTC, Meta wrote:
> On Tuesday, 28 October 2014 at 22:55:24 UTC, IgorStepanov wrote:
>> 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.
>
> Although alias this is supposed to denote subtyping, here is a 
> violation of the Liskov Substitution Principle; although S is a 
> subtype of float, there are some cases where it's invalid to 
> substitute an S for a float. This seems like a problem with 
> alias this to me. As S is aliased to float, typeof(s.val) 
> should be passed to isFloatingPoint if passing S fails.

Your issue is not relevant with alias this implementation.
isFloatingPoint is a library implemented trait, which uses 
compile-time reflections to for verifying the truth of the 
approval "T is floating point type".
If you think that isFloatingPoint implemented incorrectly, you 
may start corresponding discussion.
Otherwice, if you think that std.math.isNaN should accept user 
types which may be converted to floating point type, you may 
discuss that.
If you want simply solve you problem you may define own
auto isNaN(T)(S!(T) arg)
{
     return isNaN(cast(T)arg);
}


More information about the Digitalmars-d mailing list