<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 30, 2016, at 12:30, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Wed Jun 29 2016, Erica Sadun <<a href="http://erica-at-ericasadun.com" class="">erica-AT-ericasadun.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On Jun 29, 2016, at 3:59 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">On Wed, Jun 29, 2016 at 4:50 PM, David Sweeris <<a href="mailto:davesweeris@mac.com" class="">davesweeris@mac.com</a> <<a href="mailto:davesweeris@mac.com" class="">mailto:davesweeris@mac.com</a>>> wrote:<br class="">That’s the “as proposed” usage for getting the size of a value (from<br class=""><a href="https://gist.github.com/erica/57a64163870486468180b8bab8a6294e" class="">https://gist.github.com/erica/57a64163870486468180b8bab8a6294e</a><br class=""></blockquote><br class=""><blockquote type="cite" class=""><<a href="https://gist.github.com/erica/57a64163870486468180b8bab8a6294e" class="">https://gist.github.com/erica/57a64163870486468180b8bab8a6294e</a>>)<br class="">// Types<br class="">MemoryLayout<Int>.size // 8 <br class="">MemoryLayout<Int>.arraySpacing // 8<br class="">MemoryLayout<Int>.alignment // 8<br class=""><br class="">// Value<br class="">let x: UInt8 = 5<br class="">MemoryLayout(x).dynamicType.size // 1<br class="">MemoryLayout("hello").dynamicType.arraySpacing // 24<br class="">MemoryLayout(29.2).dynamicType.alignment // 8<br class=""><br class=""><br class="">At least, I thought that was the latest version of the proposal. Maybe I’ve gotten confused.<br class=""><br class="">There must be a typo in these examples. `MemoryLayout(x.dynamicType).size` perhaps?<br class=""></blockquote><br class="">I have listened. I have updated.<br class=""><br class=""><a href="https://gist.github.com/erica/57a64163870486468180b8bab8a6294e" class="">https://gist.github.com/erica/57a64163870486468180b8bab8a6294e</a><br class=""><br class="">// Types<br class="">MemoryLayout<Int>.size // 8<br class="">MemoryLayout<Int>.arraySpacing // 8<br class="">MemoryLayout<Int>.alignment // 8<br class=""><br class="">// Value<br class="">let x: UInt8 = 5<br class="">MemoryLayout.of(x).size // 1<br class="">MemoryLayout.of(1).size // 8<br class="">MemoryLayout.of("hello").arraySpacing // 24<br class="">MemoryLayout.of(29.2).alignment // 8<br class=""></blockquote><br class="">I am still very skeptical that anyone needs the “Value” version, and as<br class="">long as we're resyntaxing I am inclined to take it away and see how many<br class="">people complain. You can still always write it yourself.</div></div></blockquote><br class=""></div><div>Sorry to only come across this now. The proposed implementation does not work.</div><div><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div>public static func of(_ candidate : @autoclosure () -> T) -> MemoryLayout<T>.Type {</div><div> return MemoryLayout.init(candidate).dynamicType</div><div>}</div><div><br class=""></div><div>let value: Any = 2 // dynamicType is Int</div><div>let layout = MemoryLayout(value).dynamicType // inlined from above</div><div>let arrayType = [value].dynamicType</div><div><br class=""></div></blockquote><div>‘layout’ here is still 'MemoryLayout<Any>', not 'MemoryLayout<Int>', for the same reason that ‘arrayType’ is ‘Array<Any>’ rather than ‘Array<Int>’.</div><div><br class=""></div><div>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.</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>