27 lines
424 B
Plaintext
27 lines
424 B
Plaintext
interface IEdible
|
|
{
|
|
public func eat(): void;
|
|
}
|
|
|
|
template < T >
|
|
if (IsDerivedOf< T, IEdible >)
|
|
struct FoodBox
|
|
{
|
|
var food: T[];
|
|
}
|
|
|
|
class Carrot: IEdible
|
|
{
|
|
public override func eat(): void {}
|
|
}
|
|
|
|
class Car {}
|
|
|
|
func main(): void
|
|
{
|
|
var carrotBox: FoodBox< Carrot >; // OK
|
|
|
|
// var carBox: FoodBox< Car >; // Not allowed
|
|
static assert( not trait(compiles, func() { var carBox: FoodBox< Car >; } ));
|
|
}
|