-
-
Notifications
You must be signed in to change notification settings - Fork 9
InitializerList
IsaacShelton edited this page Nov 13, 2022
·
6 revisions
InitializerList
represents the type of an initializer list.
Type | Size | Possible Values | Memory Management Model | File |
---|---|---|---|---|
InitializerList |
16 bytes | Stack-Allocated Array used for initialization | None | 2.7/InitializerList.adept |
struct <$T> InitializerList (array *$T, length usize)
where
$T is any valid type
Name | Type | Description |
---|---|---|
array |
*$T |
Pointer to array of stack-allocated elements |
length |
usize |
Number of elements |
func __initializer_list__(array *$T, length usize) <$T> InitializerList
func __array__ (this *<$T> InitializerList) *$T
func __length__(this *<$T> InitializerList) usize
func __access__(this *<$T> InitializerList, index usize) *$T
implicit func __as__(initializer <long> InitializerList) <int> InitializerList
implicit func __as__(initializer <double> InitializerList) <float> InitializerList
implicit func __as__(initializer_list <$T> InitializerList) $#N $T
implicit func __as__(initializer_list <long> InitializerList) $#N int
implicit func __as__(initializer_list <double> InitializerList) $#N float
InitializerList
does not perform any memory management.
The array
points to a buffer on the stack, and all memory management of the contained values is up to the consumer of the InitializerList
.
Recycling InitializerList
values is not recommended, because user-defined implicit conversions are informally allowed to restructure the values inside an InitializerList
. An example of this, is the implicit conversion that allows <long> InitializerList
to be implicitly converted to <int> List
.
InitializerList
values can be created using initializer list literals
import basics
func main {
list_of_names <String> List = {
"Isaac",
"Andy",
"Zack",
"Ellie"
}
each String in list_of_names {
print("Hi " + it)
}
}