Skip to content

Polymorphic Prerequisites

IsaacShelton edited this page Nov 16, 2022 · 2 revisions

Polymorphic Prerequisites

In some cases, it's desirable for polymorphs to only match against certain categories of types. This is the purpose of polymorphic prerequisites. Polymorphs can be given a prerequisite by appending ~ and the name of a prerequisite to the polymorph:

$T~__primitive__

Standard Prerequisites

There are a handful of special prerequisites that the compiler defines, each made to filter different categories of types.

$T~__primitive__

The __primitive__ prerequisite can be used so that $T only matches against primitive types. The types that match are:

$T~__number__

The __number__ prerequisite can be used so that $T only matches against number-like types. The types that match are:

$T~__signed__

The __signed__ prerequisite can be used so that $T only matches against signed integer types. The types that match are:

$T~__unsigned__

The __unsigned__ prerequisite can be used so that $T only matches against unsigned integer types. The types that match are:

$T~__assign__

The __assign__ prerequisite can be used so that $T only matches against types that have an __assign__ method. An example of a type that meets this prerequisite is String.

$T~__pod__

The __pod__ prerequisite can be used so that $T only matches against types that DON'T have an __assign__ method. An example of a type that meets this prerequisite is int.

$T~__struct__

The __struct__ prerequisite is deprecated and subject to change. It can be used so that $T only matches against non-primitive types.

Extends Prerequisites

The extends MyClass prerequisite can be used to only match against classes that extend a given class (or are it).

$T extends Shape

Old Struct Prerequisites (deprecated)

Old struct prerequisites are defined like normal prerequisites, except using the name of a struct type.

$V~Vector2f

Struct prerequisites match against other struct types that contain all the fields named in the specified struct type. Whether or not the fields are of the same type is not checked.

Clone this wiki locally