Skip to content

[cxx-interop] Document support for C++ stdlib types#1403

Open
j-hui wants to merge 7 commits into
swiftlang:mainfrom
j-hui:cxx-interop-supported-types
Open

[cxx-interop] Document support for C++ stdlib types#1403
j-hui wants to merge 7 commits into
swiftlang:mainfrom
j-hui:cxx-interop-supported-types

Conversation

@j-hui
Copy link
Copy Markdown
Contributor

@j-hui j-hui commented May 4, 2026

Motivation:

This list has not been kept up to date as we've added more support for C++ interop.

Modifications:

Document which C++ stdlib types we support, especially those that we have tests for, or special compiler handling for.

Result:

The list of supported types.

j-hui added 6 commits May 4, 2026 10:38
Support for std::span has been documented elsewhere as of
swiftlang/swift@19a09f4

CxxSpan was introduced to give std::span a more ergonomic Swift API in
swiftlang/swift@e86099c
Conversions to and from Swift Durations were added in
swiftlang/swift@53fb653
Support for calling std::function in Swift added in
swiftlang/swift@2d0863a

Support for constructing std::function in Swift added in
swiftlang/swift@7fc815e

I changed the example of std::function not being supported to
std::tuple, which to my knowledge is not really supported (yet).
Group these a little bit to make it seem less like an append-only list
of C++ stdlib types.
@j-hui j-hui requested a review from a team as a code owner May 4, 2026 18:06
@j-hui
Copy link
Copy Markdown
Contributor Author

j-hui commented May 4, 2026

Copy link
Copy Markdown
Contributor

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me, but I almost wonder if we reached a point where we should only mention what is NOT supported because most things (even new containers) should just work out of the box.

@j-hui
Copy link
Copy Markdown
Contributor Author

j-hui commented May 5, 2026

I almost wonder if we reached a point where we should only mention what is NOT supported because most things (even new containers) should just work out of the box.

I was thinking that too, but I think we should also expand our documentation about what we do support and have examples using each of them

Other standard library types, like `std::function` and `std::variant`, are not
yet supported in Swift.
- `std::string`, `std::u16string`, `std::u32string`, `std::string_view`
- Specializations of `std::pair` and `std::optional`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: did you group std::pair and std::optional together for a reason?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did so here e4f57d6 since they're both small type-level combinators for structuring values

@j-hui j-hui requested review from Xazax-hun and egorzhdan May 15, 2026 00:22
- Specializations of `std::vector`, `std::array`, and `std::span`
- Specializations of `std::map`, `std::unordered_map` and `std::multimap`
- Specializations of `std::set`, `std::unordered_set` and `std::multiset`
- Specializations of `std::shared_ptr` and `std::unique_ptr`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to mention that std::unique_ptr is not fully supported in Windows?

@susmonteiro
Copy link
Copy Markdown

The change looks good to me, but I almost wonder if we reached a point where we should only mention what is NOT supported because most things (even new containers) should just work out of the box.

One example is std::list. We don't have an overlay protocol for it, but you can kind of use it in Swift. However, perhaps we should wait for Swift 6.4 to include it in the list, because with the conformance to BorrowingSequence we'll be able to iterate them.

@j-hui
Copy link
Copy Markdown
Contributor Author

j-hui commented May 19, 2026

One example is std::list. We don't have an overlay protocol for it, but you can kind of use it in Swift.

This is true, but the existence of an overlay protocol implies we guarantee a stronger level support than what you'd get out of the box + those protocols should also mean we are actively testing the support in our regression tests. For now, I think we should keep it to known good cases until we've thoroughly evaluated how well interop works for non-overlay types + gotten to a point where we can actually enumerate what doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants