module m;
void placeToEat1(T)(T t)
if (__traits(hasMember, T, "wantsBeer")
&& (__traits(hasMember, T, "wantsFries"))
//&& (!__traits(hasMember, T, "wantsShrimps")) // uncomment to help Carlos
)
{
}
void placeToEat2(T)(T t)
if (__traits(hasMember, T, "wantsBeer")
&& (__traits(hasMember, T, "wantsFries"))
&& (__traits(hasMember, T, "wantsShrimps")))
{
}
alias findPlaceToEat = placeToEat1;
alias findPlaceToEat = placeToEat2;
struct TouristType1
{
enum wantsBeer = true;
enum wantsFries = true;
}
struct TouristType2
{
enum wantsBeer = true;
enum wantsFries = true;
enum wantsShrimps = true;
}
void main()
{
TouristType1 Juan;
Juan.findPlaceToEat(); // OK Juan will not starve to death
TouristType2 Carlos;
Carlos.findPlaceToEat(); // NG, Carlos will starve to death even tho
// placeToEat2 fits more to his needs
}
Shouldn't this work for Carlos ? placeToEat2
matches more after all.