<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=""><div class="">To compute a hash, I want to loop through bytes of a trivial type. &nbsp;To get the bytes, I use withUnsafeBytes hands me a rawBufferPointer collection type. &nbsp;Great!</div><div class=""><br class=""></div><div class="">However this call also requires that the "of arg" be declared as a “var" instead of “let” because it is inout. &nbsp;So to do it generically, it forces me to make a copy to some var storage. &nbsp;</div><div class=""><br class=""></div><div class="">Since I am using&nbsp;<span style="font-family: Menlo; font-size: 11px;" class="">withUnsafeBytes&nbsp;</span>and not withUnsafeMutableBytes, though, it doesn’t seem like this copy should be necessary. &nbsp;Is there some way to avoid it? &nbsp;Is it something the compiler should be able to reason about and therefore elide? Possibly a future evolution (and something for that list)?</div><div class=""><br class=""></div><div class="">On a side note, wouldn’t it be cool if there where a way to enforce that a type was trivial?</div><div class=""><br class=""></div><div class="">Then one could write code like:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> consume&lt;T: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Trivial</span><span style="font-variant-ligatures: no-common-ligatures" class="">&gt;(value: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> copy = value</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">withUnsafeMutableBytes</span><span style="font-variant-ligatures: no-common-ligatures" class="">(of: &amp;copy) { rawBufferPointer </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// something interesting</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><br class=""></div><div class="">Always appreciate the great insights I get here.</div><div class="">Thanks as always. Best wishes,</div><div class="">Ray</div></body></html>