Concepts like c++20 with specialized overload resolution.

vushu danvu.hustle at gmail.com
Sat May 27 13:23:38 UTC 2023


```
template <typename T>
concept HasMagma = requires(T l) { l.magma(); };

struct LavaMan {
   void magma() { std::cout << " LavaMan is throwing LAVA" << 
std::endl; }
};

struct FakeVulcano {
   void try_making_lava() { std::cout << " Making fake lava" << 
std::endl; }
};

void make_lava(HasMagma auto& lava) {
     lava.magma();
}

void make_lava(auto& lava_thing){
     lava_thing.try_making_lava();
}

int main() {
   LavaMan v;
   FakeVulcano l;
   make_lava(l);
   make_lava(v);
   return 0;
}
```

results in:
```
  Making fake lava
  LavaMan is throwing LAVA
```

Is there something equivalent in dlang, doesn't seem like d 
support specialized overload?



More information about the Digitalmars-d-learn mailing list