Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
import morfa.type.traits;
|
||||
|
||||
template < T >
|
||||
alias IsEdible = HasMember< T, "eat" >;
|
||||
|
||||
template < T >
|
||||
if (IsEdible< T >)
|
||||
struct FoodBox
|
||||
{
|
||||
var food: T[];
|
||||
}
|
||||
|
||||
struct Carrot
|
||||
{
|
||||
func eat(): void {}
|
||||
}
|
||||
|
||||
struct Car {}
|
||||
|
||||
func main(): void
|
||||
{
|
||||
var carrotBox: FoodBox< Carrot >; // OK
|
||||
carrotBox.food ~= Carrot(); // Adds a carrot
|
||||
|
||||
// var carBox: FoodBox< Car >; // Not allowed
|
||||
static assert( not trait(compiles, func() { var carBox: FoodBox< Car >; } ));
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
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 >; } ));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue