Skip to content

[cxx-interop] NFC: Improve documentation comments #62869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions stdlib/public/Cxx/CxxConvertibleToCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ internal func forEachElement<C: CxxConvertibleToCollection>(
}

extension Array {
/// Creates an array containing the elements of a C++ collection.
/// Creates an array containing the elements of a C++ container.
///
/// This initializer copies each element of the C++ collection to a new Swift
/// array.
/// This initializes the array by copying every element of the C++ container.
///
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment "This initializer copies each element of the C++ container to a new Swift array." might be misinterpreted to mean the init is creating a new Swift Array internally. You could instead say "Initializes the array (or self) by copying every element of the C++ container".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

/// - Complexity: O(*n*), where *n* is the number of elements in the C++
/// collection.
/// container when each element is copied in O(1). Note that this might not
/// be true for certain C++ types, e.g. those with a custom copy
/// constructor that performs additional logic.
public init<C: CxxConvertibleToCollection>(_ c: C)
where C.RawIterator.Pointee == Element {

Expand All @@ -54,13 +55,14 @@ extension Array {
}

extension Set {
/// Creates an set containing the elements of a C++ collection.
/// Creates an set containing the elements of a C++ container.
///
/// This initializer copies each element of the C++ collection to a new Swift
/// set.
/// This initializes the set by copying every element of the C++ container.
///
/// - Complexity: O(*n*), where *n* is the number of elements in the C++
/// collection.
/// container when each element is copied in O(1). Note that this might not
/// be true for certain C++ types, e.g. those with a custom copy
/// constructor that performs additional logic.
public init<C: CxxConvertibleToCollection>(_ c: C)
where C.RawIterator.Pointee == Element {

Expand Down
6 changes: 6 additions & 0 deletions stdlib/public/Cxx/CxxSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public struct CxxIterator<T>: IteratorProtocol where T: CxxSequence {
}

extension CxxSequence {
/// Returns an iterator over the elements of this C++ container.
///
/// - Complexity: O(*n*), where *n* is the number of elements in the C++
/// container when each element is copied in O(1). Note that this might not
/// be true for certain C++ types, e.g. those with a custom copy
/// constructor that performs additional logic.
@inlinable
public func makeIterator() -> CxxIterator<Self> {
return CxxIterator(sequence: self)
Expand Down