-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTupleMetadata.swift
More file actions
47 lines (37 loc) · 824 Bytes
/
TupleMetadata.swift
File metadata and controls
47 lines (37 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public struct TupleMetadata: Layout {
typealias Layout = (
base: Metadata.Layout,
numberOfElements: Int,
labels: UnsafePointer<CChar>?
)
let pointer: UnsafeRawPointer
init(_ ptr: UnsafeRawPointer) {
self.pointer = ptr
}
}
extension TupleMetadata: RandomAccessCollection {
public struct Element {
let storage: (Metadata, Int)
public var type: Metadata {
storage.0
}
public var offset: Int {
storage.1
}
}
public var startIndex: Int {
0
}
public var endIndex: Int {
layout.numberOfElements
}
public func index(after i: Int) -> Int {
i + 1
}
public func index(before i: Int) -> Int {
i - 1
}
public subscript(position: Int) -> Element {
(trailing + position * MemoryLayout<Element>.size).load(as: Element.self)
}
}