Poor Carlos does not manage to find where to eat
user1234
user1234 at 12.de
Sat Sep 21 04:29:15 UTC 2024
```d
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.
More information about the Digitalmars-d-learn
mailing list