-
-
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> InitializerListfunc __array__ (this *<$T> InitializerList) *$Tfunc __length__(this *<$T> InitializerList) usizefunc __access__(this *<$T> InitializerList, index usize) *$Timplicit func __as__(initializer <long> InitializerList) <int> InitializerListimplicit func __as__(initializer <double> InitializerList) <float> InitializerListimplicit func __as__(initializer_list <$T> InitializerList) $#N $Timplicit func __as__(initializer_list <long> InitializerList) $#N intimplicit 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)
}
}