Skip to content

[libc++] Make common_iterator's data member private #72564

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 1 commit into from
Nov 21, 2023

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Nov 16, 2023

Fixes #71498

@ldionne ldionne requested a review from a team as a code owner November 16, 2023 20:16
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 16, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 16, 2023

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

Fixes #71498


Full diff: https://github.com/llvm/llvm-project/pull/72564.diff

1 Files Affected:

  • (modified) libcxx/include/__iterator/common_iterator.h (+4-1)
diff --git a/libcxx/include/__iterator/common_iterator.h b/libcxx/include/__iterator/common_iterator.h
index 95e248d83f4b460..7750cf0f7638d6b 100644
--- a/libcxx/include/__iterator/common_iterator.h
+++ b/libcxx/include/__iterator/common_iterator.h
@@ -63,9 +63,12 @@ class common_iterator {
     iter_value_t<_Iter> __value_;
   };
 
-public:
   variant<_Iter, _Sent> __hold_;
+  template<input_or_output_iterator _OtherIter, sentinel_for<_Iter> _OtherSent>
+    requires (!same_as<_OtherIter, _OtherSent> && copyable<_OtherIter>)
+  friend class common_iterator;
 
+public:
   _LIBCPP_HIDE_FROM_ABI common_iterator() requires default_initializable<_Iter> = default;
 
   _LIBCPP_HIDE_FROM_ABI constexpr common_iterator(_Iter __i) : __hold_(in_place_type<_Iter>, _VSTD::move(__i)) {}

@ldionne ldionne force-pushed the review/common-iterator-public branch from 9949a45 to 0592fbe Compare November 20, 2023 16:32
@hawkinsw
Copy link
Contributor

Not that my opinion matters for much, but I see nothing wrong with this approach.

@ldionne ldionne merged commit ca9b1d1 into llvm:main Nov 21, 2023
@ldionne ldionne deleted the review/common-iterator-public branch November 21, 2023 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<iterator>: common_iterator's data member is public
3 participants