Add pointee: borrowing T
to std.shared_ptr<T>
for C++ interop
#78296
Labels
pointee: borrowing T
to std.shared_ptr<T>
for C++ interop
#78296
Motivation
Currently,
std.shared_ptr<T>.pointee
actually copiesT
, which is a big issue for pretty much every type wrapped in astd::shared_ptr
that I have worked with - they're wrapped in ashared_ptr
for a reason.This is not only a performance concern, but maybe even a fundamental issue - some types are not expected to be copied and might delete resources unsafely in their destructors.
Proposed solution
It would be dope to add an API that allows us to get a
borrowing T
to avoid a copy.Also, maybe this even allows for using non-copyable C++ types in Swift?
Alternatives considered
I can add
SWIFT_IMMORTAL_REFERENCE
to every type that I plan on using inside of astd::shared_ptr
, but this isn't ideal either, as sometimes I use external types that are not written by me.Additional information
No response
The text was updated successfully, but these errors were encountered: