Post

Replies

Boosts

Views

Activity

Reply to Pass Swift Array To C++ As A std::vector
In my current use case, I want to pass the data from Swift to C++ without any further modifications needing to be fed back into Swift. I can modify both sides of this code, and I have found a workaround that works for the moment. But I would like to avoid workarounds, especially when it seems like there should be some bridging for this use case. In regards to move vs copy -- move would be ideal. But I didn't go further with this because of the first issue.
Jan ’24
Reply to Pass Swift Array To C++ As A std::vector
I have looked at that link a few times and it does not solve my problem. It definitely would allow me to pass a std::vector from Swift into C++, but it is not the same as bridging between a Swift array and a C++ vector. Using this method would be much slower because it would require calling push_back multiple times while iterating through an array. I did find a temporary workaround that at least got me going again. Instead of passing a std::vector in my C++ function, I switched to using a pointer and size parameter. I could then using an UnsafeRawPointer and the count to make the contents of the array available to the C++ code. From within C++, I created the std::vector. The downside is that this requires a memcpy, so this would not be ideal for large arrays. I still would like to know if there is any bridging between Swift arrays and C++ std::vector (or std::array) that could be used for this case.
Jan ’24