[libcxx-commits] [libcxx] [libc++] Simplify the implementation of conditional a bit (PR #199916)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 27 03:12:39 PDT 2026


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

We can use our internal `_If` instead of specializing `conditional` for selecting the appropriate type.


>From 9b1a8d1b513bd8243c6310264cc87687d6fce771 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 27 May 2026 12:11:48 +0200
Subject: [PATCH] [libc++] Simplify the implementation of conditional a bit

---
 libcxx/include/__type_traits/conditional.h | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/libcxx/include/__type_traits/conditional.h b/libcxx/include/__type_traits/conditional.h
index 71882fb1917b1..0daa7737bed06 100644
--- a/libcxx/include/__type_traits/conditional.h
+++ b/libcxx/include/__type_traits/conditional.h
@@ -35,20 +35,10 @@ struct _IfImpl<false> {
 template <bool _Cond, class _IfRes, class _ElseRes>
 using _If _LIBCPP_NODEBUG = typename _IfImpl<_Cond>::template _Select<_IfRes, _ElseRes>;
 
-template <bool _Bp, class _If, class _Then>
+template <bool _Bp, class _IfRes, class _ElseRes>
 struct _LIBCPP_NO_SPECIALIZATIONS conditional {
-  using type _LIBCPP_NODEBUG = _If;
-};
-
-_LIBCPP_DIAGNOSTIC_PUSH
-#if __has_warning("-Winvalid-specialization")
-_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
-#endif
-template <class _If, class _Then>
-struct conditional<false, _If, _Then> {
-  using type _LIBCPP_NODEBUG = _Then;
+  using type _LIBCPP_NODEBUG = _If<_Bp, _IfRes, _ElseRes>;
 };
-_LIBCPP_DIAGNOSTIC_POP
 
 #if _LIBCPP_STD_VER >= 14
 template <bool _Bp, class _IfRes, class _ElseRes>



More information about the libcxx-commits mailing list