Skip to content

InitializerList

IsaacShelton edited this page Nov 13, 2022 · 6 revisions

InitializerList

InitializerList represents the type of an initializer list.

Specifications

Type Size Possible Values Memory Management Model File
InitializerList 16 bytes Stack-Allocated Array used for initialization None 2.7/InitializerList.adept

Definition

struct <$T> InitializerList (array *$T, length usize)

where

$T is any valid type

Fields

Name Type Description
array *$T Pointer to array of stack-allocated elements
length usize Number of elements

Value Management Definitions

  • 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

Memory Management

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.

Multiple Uses

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.

Creation

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)
    }
}
Clone this wiki locally