MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | CONCEPT |
| 2 | unions |
| 3 | |
| 4 | DESCRIPTION |
| 5 | Unions types are a declaration at compile time that a variable, |
| 6 | function parameter or function return value can be one of |
| 7 | several types. |
| 8 | |
| 9 | Except for type checks using #pragma rtt_checks they have no |
| 10 | impact at runtime. There is no runtime union type, the concrete |
| 11 | value type is one of the possibilities of the union type. |
| 12 | |
| 13 | Union types have no type names for themselves, they are declared |
| 14 | anonymously with the declaration of the variable, function |
| 15 | parameter or return type: |
| 16 | |
| 17 | int|string var; |
| 18 | int|float fun(object|closure f); |
| 19 | |
| 20 | When using union types as array member types they must be |
| 21 | enclosed with < >: |
| 22 | |
| 23 | <int|string>* arr; /* An array of ints and strings. */ |
| 24 | int*|string* arr; /* Either an array of ints or |
| 25 | an array of strings. */ |
| 26 | |
| 27 | /* There must be a whitespace between two consecutive < |
| 28 | to be not confused with the << operator: */ |
| 29 | < <int|string>*|object >* arr; |
| 30 | |