[swift-evolution] [Pitch] Add the DefaultConstructible protocol to the standard library

Dave Abrahams dabrahams at apple.com
Mon Dec 26 16:52:58 CST 2016


on Mon Dec 26 2016, Tony Allevato <swift-evolution at swift.org> wrote:

> On Mon, Dec 26, 2016 at 1:46 PM Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
>> This sounds like what UnsafeMutableRawBufferPointer was designed for, no?
>>
>
> I can understand the desire to write an algorithm like this without going
> down to unsafe territory, but yes, that's probably the right
> approach—especially since the idea of a non-optional but
> not-yet-initialized value is inherently unsafe.

It's *very* rarely necessary to drop down to unsafe code for these
cases.  If you can create a Sequence/Collection that (lazily) represents
the values you need in the array, you can easily initialize the array at
the point where it's needed without doing a 2-phase dance.

-- 
-Dave



More information about the swift-evolution mailing list