RosettaCodeData/Task/Constrained-genericity/D/constrained-genericity-2.d
Ingy döt Net 764da6cbbb CDE
2013-04-10 16:57:12 -07:00

17 lines
260 B
D

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
}