[libcxx-commits] [libcxx] [libc++] Simplify some deduction guides (PR #197878)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 15 00:52:24 PDT 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/197878

None

>From c89df5a85cb82f2358410982e80d504d6a2257ed Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Fri, 15 May 2026 09:52:04 +0200
Subject: [PATCH] [libc++] Simplify some deduction guides

---
 libcxx/include/__vector/vector.h | 11 ++---------
 libcxx/include/deque             | 11 ++---------
 libcxx/include/forward_list      | 12 +++---------
 libcxx/include/list              | 11 ++---------
 4 files changed, 9 insertions(+), 36 deletions(-)

diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index 1804de2a120f8..053a829f626f8 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -822,15 +822,8 @@ class vector {
 #if _LIBCPP_STD_VER >= 17
 template <class _InputIterator,
           class _Alloc = allocator<__iterator_value_type<_InputIterator>>,
-          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
-          class        = enable_if_t<__is_allocator_v<_Alloc>>>
-vector(_InputIterator, _InputIterator) -> vector<__iterator_value_type<_InputIterator>, _Alloc>;
-
-template <class _InputIterator,
-          class _Alloc,
-          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
-          class = enable_if_t<__is_allocator_v<_Alloc>>>
-vector(_InputIterator, _InputIterator, _Alloc) -> vector<__iterator_value_type<_InputIterator>, _Alloc>;
+          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value && __is_allocator_v<_Alloc>>>
+vector(_InputIterator, _InputIterator, _Alloc = _Alloc()) -> vector<__iterator_value_type<_InputIterator>, _Alloc>;
 #endif
 
 #if _LIBCPP_STD_VER >= 23
diff --git a/libcxx/include/deque b/libcxx/include/deque
index c8c6889f1a165..a5871d7620239 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -1291,15 +1291,8 @@ _LIBCPP_CONSTEXPR const typename allocator_traits<_Alloc>::difference_type deque
 #  if _LIBCPP_STD_VER >= 17
 template <class _InputIterator,
           class _Alloc = allocator<__iterator_value_type<_InputIterator>>,
-          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
-          class        = enable_if_t<__is_allocator_v<_Alloc>>>
-deque(_InputIterator, _InputIterator) -> deque<__iterator_value_type<_InputIterator>, _Alloc>;
-
-template <class _InputIterator,
-          class _Alloc,
-          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
-          class = enable_if_t<__is_allocator_v<_Alloc>>>
-deque(_InputIterator, _InputIterator, _Alloc) -> deque<__iterator_value_type<_InputIterator>, _Alloc>;
+          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value && __is_allocator_v<_Alloc>>>
+deque(_InputIterator, _InputIterator, _Alloc = _Alloc()) -> deque<__iterator_value_type<_InputIterator>, _Alloc>;
 #  endif
 
 #  if _LIBCPP_STD_VER >= 23
diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index 35afb7301f480..7056b7602b61d 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -910,15 +910,9 @@ private:
 #  if _LIBCPP_STD_VER >= 17
 template <class _InputIterator,
           class _Alloc = allocator<__iterator_value_type<_InputIterator>>,
-          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
-          class        = enable_if_t<__is_allocator_v<_Alloc>>>
-forward_list(_InputIterator, _InputIterator) -> forward_list<__iterator_value_type<_InputIterator>, _Alloc>;
-
-template <class _InputIterator,
-          class _Alloc,
-          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
-          class = enable_if_t<__is_allocator_v<_Alloc>>>
-forward_list(_InputIterator, _InputIterator, _Alloc) -> forward_list<__iterator_value_type<_InputIterator>, _Alloc>;
+          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value && __is_allocator_v<_Alloc>>>
+forward_list(_InputIterator, _InputIterator, _Alloc = _Alloc())
+    -> forward_list<__iterator_value_type<_InputIterator>, _Alloc>;
 #  endif
 
 #  if _LIBCPP_STD_VER >= 23
diff --git a/libcxx/include/list b/libcxx/include/list
index a5c84cad51489..164e37da84d3c 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -1003,15 +1003,8 @@ private:
 #  if _LIBCPP_STD_VER >= 17
 template <class _InputIterator,
           class _Alloc = allocator<__iterator_value_type<_InputIterator>>,
-          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
-          class        = enable_if_t<__is_allocator_v<_Alloc>>>
-list(_InputIterator, _InputIterator) -> list<__iterator_value_type<_InputIterator>, _Alloc>;
-
-template <class _InputIterator,
-          class _Alloc,
-          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
-          class = enable_if_t<__is_allocator_v<_Alloc>>>
-list(_InputIterator, _InputIterator, _Alloc) -> list<__iterator_value_type<_InputIterator>, _Alloc>;
+          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value && __is_allocator_v<_Alloc>>>
+list(_InputIterator, _InputIterator, _Alloc = _Alloc()) -> list<__iterator_value_type<_InputIterator>, _Alloc>;
 #  endif
 
 #  if _LIBCPP_STD_VER >= 23



More information about the libcxx-commits mailing list