27 lines
424 B
Text
27 lines
424 B
Text
|
|
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 >; } ));
|
||
|
|
}
|