-
-
Notifications
You must be signed in to change notification settings - Fork 9
Optional
Optional
represents the type of a value that might exist.
Type | Size | Memory Management Model | File |
---|---|---|---|
Optional |
? bytes | Scoped | 2.7/Optional.adept |
struct <$T> Optional (value $T, has bool)
where
$T is any valid type
Name | Type | Description |
---|---|---|
has |
bool |
Whether a value exists |
value |
$T |
Wrapped value, only exists if has is true |
verbatim func __defer__(this *<$T> Optional)
func __assign__(this *<$T> Optional, other <$T> Optional)
optional.value
is freed at the end of the scope if optional.has
is true.
-
func none() <$T> Optional
Returns an empty optional. Should be used with
~>
operator likenone() ~> <int> Optional
. -
func some(contained POD $T) <$T> Optional
Returns an optional with a contained value. The contained value is copied byte for byte, so some values may need modifications before being given to this function.
-
func set(this *<$T> Optional, value POD $T) void
Sets an optional to a value. The value is copied byte for byte, so some values may need modifications before being given to this function.
-
func get(this *<$T> Optional) $T
Gets the contained value of an optional.
-
func getPointer(this *<$T> Optional) *$T
Gets a pointer to the contained value of an optional.
-
func rid(this *<$T> Optional) void
Sets an optional to not contain anything.
-
func assign(this *<$T> Optional, value POD $T) void
Destroys and clears the internal value of an optional, and then stores the new value using standard assignment semantics
this.value.__defer__() memset(&this.value, 0, sizeof(this.value)) this.value = value this.has = true
-
func assignPOD(this *<$T> Optional, value POD $T) void
Destroys and clears the internal value of an optional, and then stores the new value using POD assignment semantics
this.value.__defer__() memset(&this.value, 0, sizeof(this.value)) this.value = POD value this.has = true
These functions are undocumented as they are likely to change in the future.
func isSome(this *<$T> Optional, out captured *$T) bool
func map(this *<$T> Optional, function func($~T) $S) <$S> Optional
func mapPOD(this *<$T> Optional, function func($~T) $S) <$S> Optional
func pass(this *<$T> Optional) <$T> Optional
-
func toString(_ <$T> Optional) String = delete {}
Since it cannot be known whether we are responsible for freeing
_.value
, this call makes no sense
#default Optional_error_no_value true