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

Hooman Mehr hooman at mac.com
Tue Jun 28 20:27:48 CDT 2016


How about we get rid of dynamicType by adding instance level properties as well:

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) }
    
    public var size: Int { return sizeof(T) }
    public var interval: Int { return strideof(T) }
    public 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).size) // 8
print(MemoryLayout(x).interval) // 8
print(MemoryLayout(x).alignment) // 8

> On Jun 28, 2016, at 5:08 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> on Tue Jun 28 2016, Brandon Knope <bknope-AT-me.com> wrote:
> 
>> Isn't dynamicType possibly changing soon to a method?
> 
> A free function, I think.
> 
>> This could look much different
> 
> Yes, It will be uglier.  But this very uncommon case is not important to
> optimize for beauty.
> 
> -- 
> Dave
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list