Simple and effective approaches to constraint error messages

Sebastiaan Koppe via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 25 13:50:09 PDT 2016


On Monday, 25 April 2016 at 17:52:58 UTC, Andrei Alexandrescu 
wrote:
>
> Destroy!
>
> Andrei

What about overloaded functions with complex constraints? How 
would the errors look when none of the overloaded constraints 
fully match?

auto fun(T)(T t) if (hasWheels!T && canFly!T) {}

auto fun(T)(T t) if (canFloat!T && isAirtight!T) {}

struct A
{
// suppose it has wheels and floats, but can't fly nor is it 
airtight
}

void main()
{
   A a;
   a.fun(); // `Error: either make A fly or airtight`
}


More information about the Digitalmars-d mailing list