RosettaCodeData/Task/Constrained-genericity/D/constrained-genericity-2.d

18 lines
260 B
D
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
interface IEdible { void eat(); }
struct FoodBox(T : IEdible) {
T[] food;
alias food this;
}
class Carrot : IEdible {
void eat() {}
}
class Car {}
void main() {
FoodBox!Carrot carrotBox; // OK
//FoodBox!Car carBox; // Not allowed
}