Skip to content

[libc++] Simplify __unwrap_iter a bit#175153

Merged
philnik777 merged 1 commit intollvm:mainfrom
philnik777:simplify_unwrap_iter
Jan 13, 2026
Merged

[libc++] Simplify __unwrap_iter a bit#175153
philnik777 merged 1 commit intollvm:mainfrom
philnik777:simplify_unwrap_iter

Conversation

@philnik777
Copy link
Copy Markdown
Contributor

__unwrap_iter doesn't need to SFINAE away, so we can just check inside the function body whether an iterator is copy constructible. This reduces the overload set, improving compile times a bit.

@philnik777 philnik777 marked this pull request as ready for review January 13, 2026 16:00
@philnik777 philnik777 requested a review from a team as a code owner January 13, 2026 16:00
@philnik777 philnik777 merged commit 7581c70 into llvm:main Jan 13, 2026
135 of 136 checks passed
@philnik777 philnik777 deleted the simplify_unwrap_iter branch January 13, 2026 16:01
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 13, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 13, 2026

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

__unwrap_iter doesn't need to SFINAE away, so we can just check inside the function body whether an iterator is copy constructible. This reduces the overload set, improving compile times a bit.


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

1 Files Affected:

  • (modified) libcxx/include/__algorithm/unwrap_iter.h (+8-10)
diff --git a/libcxx/include/__algorithm/unwrap_iter.h b/libcxx/include/__algorithm/unwrap_iter.h
index b66a682e765fa..ea862cd2f6f30 100644
--- a/libcxx/include/__algorithm/unwrap_iter.h
+++ b/libcxx/include/__algorithm/unwrap_iter.h
@@ -57,21 +57,19 @@ struct __unwrap_iter_impl<_Iter, true> {
   }
 };
 
-template <class _Iter,
-          class _Impl                                             = __unwrap_iter_impl<_Iter>,
-          __enable_if_t<is_copy_constructible<_Iter>::value, int> = 0>
+template <class _Iter, class _Impl = __unwrap_iter_impl<_Iter> >
 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 decltype(_Impl::__unwrap(std::declval<_Iter>()))
 __unwrap_iter(_Iter __i) _NOEXCEPT {
-  return _Impl::__unwrap(__i);
-}
-
 // Allow input_iterators to be passed to __unwrap_iter (but not __rewrap_iter)
 #if _LIBCPP_STD_VER >= 20
-template <class _Iter, __enable_if_t<!is_copy_constructible<_Iter>::value, int> = 0>
-inline _LIBCPP_HIDE_FROM_ABI constexpr _Iter __unwrap_iter(_Iter __i) noexcept {
-  return __i;
-}
+  if constexpr (!is_copy_constructible_v<_Iter>) {
+    return __i;
+  } else
 #endif
+  {
+    return _Impl::__unwrap(__i);
+  }
+}
 
 template <class _OrigIter, class _Iter, class _Impl = __unwrap_iter_impl<_OrigIter> >
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _OrigIter __rewrap_iter(_OrigIter __orig_iter, _Iter __iter) _NOEXCEPT {

Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
`__unwrap_iter` doesn't need to SFINAE away, so we can just check inside
the function body whether an iterator is copy constructible. This
reduces the overload set, improving compile times a bit.
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.

2 participants