[swift-evolution] [Review] SE-0101: Rename sizeof and related functions to comply with API Guidelines

Erica Sadun erica at ericasadun.com
Tue Jun 28 15:53:58 CDT 2016


On Jun 28, 2016, at 12:11 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>>> I think it would.  It would *really* help if someone would prepare a
>>> patch that uses both APIs so we could see how the resulting code looks
>>> in practice. :-)
>>> 
>>> -- 
>>> Dave
>> 
>> Here you go:
>> https://gist.github.com/erica/57a64163870486468180b8bab8a6294e
>> <https://gist.github.com/erica/57a64163870486468180b8bab8a6294e <https://gist.github.com/erica/57a64163870486468180b8bab8a6294e>>
> 
> Thanks for the proposal, Erica.  It contains some errors that I pointed
> out in a comment on the Gist.  Care to fix those?
> 

public struct MemoryLayout<T> {
    public static var size: Int { return sizeof(T) }
    public static var interval: Int { return strideof(T) }
    public static var alignment: Int { return alignof(T) }
    
    init(_ : @autoclosure () -> T) {}
}

print(MemoryLayout<Int>.size) // 8
print(MemoryLayout<Int>.interval) // 8
print(MemoryLayout<Int>.alignment) // 8

let x = 8

print(MemoryLayout(x).dynamicType.size) // 8
print(MemoryLayout(x).dynamicType.interval) // 8
print(MemoryLayout(x).dynamicType.alignment) // 8

-- E


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160628/a48f1a53/attachment.html>


More information about the swift-evolution mailing list