Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Constrained-genericity/D/constrained-genericity-1.d
Normal file
19
Task/Constrained-genericity/D/constrained-genericity-1.d
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
enum IsEdible(T) = is(typeof(T.eat));
|
||||
|
||||
struct FoodBox(T) if (IsEdible!T) {
|
||||
T[] food;
|
||||
alias food this;
|
||||
}
|
||||
|
||||
struct Carrot {
|
||||
void eat() {}
|
||||
}
|
||||
|
||||
static struct Car {}
|
||||
|
||||
void main() {
|
||||
FoodBox!Carrot carrotsBox; // OK
|
||||
carrotsBox ~= Carrot(); // Adds a carrot
|
||||
|
||||
//FoodBox!Car carsBox; // Not allowed
|
||||
}
|
||||
17
Task/Constrained-genericity/D/constrained-genericity-2.d
Normal file
17
Task/Constrained-genericity/D/constrained-genericity-2.d
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue