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

Erica Sadun erica at ericasadun.com
Tue Jul 12 15:57:45 CDT 2016


We removed "of" from the final version:

https://github.com/apple/swift-evolution/blob/master/proposals/0101-standardizing-sizeof-naming.md <https://github.com/apple/swift-evolution/blob/master/proposals/0101-standardizing-sizeof-naming.md>

And moved it to "If for some reason, the core team decides that there's a compelling reason to include value calls, an implementation might look something like this" instead.

Dave expressed that this should be something that operates on types not values.

-- E


> On Jul 12, 2016, at 2:43 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> 
> Sorry to only come across this now. The proposed implementation does not work.
> 
> public static func of(_ candidate : @autoclosure () -> T) -> MemoryLayout<T>.Type {
>   return MemoryLayout.init(candidate).dynamicType
> }
> 
> let value: Any = 2 // dynamicType is Int
> let layout = MemoryLayout(value).dynamicType // inlined from above
> let arrayType = [value].dynamicType
> 
> ‘layout’ here is still 'MemoryLayout<Any>', not 'MemoryLayout<Int>', for the same reason that ‘arrayType’ is ‘Array<Any>’ rather than ‘Array<Int>’.
> 
> If we want to support sizeofValue et al, we’d need to make these instance properties rather than static properties, and may then want to give up on the struct being generic.
> 
> Jordan

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


More information about the swift-evolution mailing list