Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -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 >; } ));
}

View file

@ -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 >; } ));
}