-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Merge insert/emplace(const_iterator, Args...) implementations #166470
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
870d147 to
04f02fa
Compare
04f02fa to
f96ed10
Compare
Member
|
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesFull diff: https://github.com/llvm/llvm-project/pull/166470.diff 1 Files Affected:
diff --git a/libcxx/include/deque b/libcxx/include/deque
index ab41b9db9de26..cbf4b98e07a5b 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -779,6 +779,10 @@ public:
// 23.2.2.3 modifiers:
_LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __v);
_LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __v);
+
+ template <class... _Args>
+ _LIBCPP_HIDE_FROM_ABI iterator __emplace(const_iterator __p, _Args&&... __args);
+
# ifndef _LIBCPP_CXX03_LANG
# if _LIBCPP_STD_VER >= 17
template <class... _Args>
@@ -791,8 +795,11 @@ public:
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
# endif
+
template <class... _Args>
- _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);
+ _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args) {
+ return __emplace(__p, std::forward<_Args>(__args)...);
+ }
_LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __v);
_LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __v);
@@ -809,13 +816,13 @@ public:
}
# endif
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v);
+ _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) { return __emplace(__p, std::move(__v)); }
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, initializer_list<value_type> __il) {
return insert(__p, __il.begin(), __il.end());
}
# endif // _LIBCPP_CXX03_LANG
- _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v);
+ _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) { return __emplace(__p, __v); }
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __v);
template <class _InputIter, __enable_if_t<__has_exactly_input_iterator_category<_InputIter>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InputIter __f, _InputIter __l);
@@ -1661,56 +1668,11 @@ deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) {
return *begin();
# endif
}
-
-template <class _Tp, class _Allocator>
-typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) {
- size_type __pos = __p - begin();
- size_type __to_end = size() - __pos;
- allocator_type& __a = __alloc();
- if (__pos < __to_end) { // insert by shifting things backward
- if (__front_spare() == 0)
- __add_front_capacity();
- // __front_spare() >= 1
- __annotate_increase_front(1);
- if (__pos == 0) {
- __alloc_traits::construct(__a, std::addressof(*--begin()), std::move(__v));
- --__start_;
- ++__size();
- } else {
- iterator __b = begin();
- iterator __bm1 = std::prev(__b);
- __alloc_traits::construct(__a, std::addressof(*__bm1), std::move(*__b));
- --__start_;
- ++__size();
- if (__pos > 1)
- __b = std::move(std::next(__b), __b + __pos, __b);
- *__b = std::move(__v);
- }
- } else { // insert by shifting things forward
- if (__back_spare() == 0)
- __add_back_capacity();
- // __back_capacity >= 1
- __annotate_increase_back(1);
- size_type __de = size() - __pos;
- if (__de == 0) {
- __alloc_traits::construct(__a, std::addressof(*end()), std::move(__v));
- ++__size();
- } else {
- iterator __e = end();
- iterator __em1 = std::prev(__e);
- __alloc_traits::construct(__a, std::addressof(*__e), std::move(*__em1));
- ++__size();
- if (__de > 1)
- __e = std::move_backward(__e - __de, __em1, __e);
- *--__e = std::move(__v);
- }
- }
- return begin() + __pos;
-}
+# endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
template <class... _Args>
-typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) {
+typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::__emplace(const_iterator __p, _Args&&... __args) {
size_type __pos = __p - begin();
size_type __to_end = size() - __pos;
allocator_type& __a = __alloc();
@@ -1757,60 +1719,6 @@ typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::emplace(const_
return begin() + __pos;
}
-# endif // _LIBCPP_CXX03_LANG
-
-template <class _Tp, class _Allocator>
-typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) {
- size_type __pos = __p - begin();
- size_type __to_end = size() - __pos;
- allocator_type& __a = __alloc();
- if (__pos < __to_end) { // insert by shifting things backward
- if (__front_spare() == 0)
- __add_front_capacity();
- // __front_spare() >= 1
- __annotate_increase_front(1);
- if (__pos == 0) {
- __alloc_traits::construct(__a, std::addressof(*--begin()), __v);
- --__start_;
- ++__size();
- } else {
- const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
- iterator __b = begin();
- iterator __bm1 = std::prev(__b);
- if (__vt == pointer_traits<const_pointer>::pointer_to(*__b))
- __vt = pointer_traits<const_pointer>::pointer_to(*__bm1);
- __alloc_traits::construct(__a, std::addressof(*__bm1), std::move(*__b));
- --__start_;
- ++__size();
- if (__pos > 1)
- __b = __move_and_check(std::next(__b), __b + __pos, __b, __vt);
- *__b = *__vt;
- }
- } else { // insert by shifting things forward
- if (__back_spare() == 0)
- __add_back_capacity();
- // __back_capacity >= 1
- __annotate_increase_back(1);
- size_type __de = size() - __pos;
- if (__de == 0) {
- __alloc_traits::construct(__a, std::addressof(*end()), __v);
- ++__size();
- } else {
- const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
- iterator __e = end();
- iterator __em1 = std::prev(__e);
- if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1))
- __vt = pointer_traits<const_pointer>::pointer_to(*__e);
- __alloc_traits::construct(__a, std::addressof(*__e), std::move(*__em1));
- ++__size();
- if (__de > 1)
- __e = __move_backward_and_check(__e - __de, __em1, __e, __vt);
- *--__e = *__vt;
- }
- }
- return begin() + __pos;
-}
-
template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) {
|
ckoparkar
added a commit
to ckoparkar/llvm-project
that referenced
this pull request
Nov 10, 2025
* main: (1028 commits) [clang][DebugInfo] Attach `DISubprogram` to additional call variants (llvm#166202) [C2y] Claim nonconformance to WG14 N3348 (llvm#166966) [X86] 2012-01-10-UndefExceptionEdge.ll - regenerate test checks (llvm#167307) Remove unused standard headers: <string>, <optional>, <numeric>, <tuple> (llvm#167232) [DebugInfo] Add Verifier check for incorrectly-scoped retainedNodes (llvm#166855) [VPlan] Don't apply predication discount to non-originally-predicated blocks (llvm#160449) [libc++] Avoid overloaded `operator,` for (`T`, `Iter`) cases (llvm#161049) [tools][llc] Make save-stats.ll test target independent (llvm#167238) [AArch64] Fallback to PRFUM for PRFM with negative or unaligned offset (llvm#166756) [X86] ldexp-avx512.ll - add v8f16/v16f16/v32f16 test coverage for llvm#165694 (llvm#167294) [DropAssumes] Drop dereferenceable assumptions after vectorization. (llvm#166947) [VPlan] Simplify branch-cond with getVectorTripCount (llvm#155604) Remove unused <algorithm> inclusion (llvm#166942) [AArch64] Combine subtract with borrow to SBC. (llvm#165271) [AArch64][SVE] Avoid redundant extend of unsigned i8/i16 extracts. (llvm#165863) [SPIRV] Fix failing assertion in SPIRVAsmPrinter (llvm#166909) [libc++] Merge insert/emplace(const_iterator, Args...) implementations (llvm#166470) [libc++] Replace __libcpp_is_final with a variable template (llvm#167137) [gn build] Port 152bda7 [libc++] Replace the last uses of __tuple_types with __type_list (llvm#167214) ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.