[libcxx-commits] [PATCH] D115100: [libc++] Enable the optimized _IsSame on GCC as well as Clang.
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 15 17:20:46 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c0ea7488bc0: [libc++] Enable the optimized _IsSame on GCC as well as Clang. (authored by arthur.j.odwyer).
Changed prior to commit:
https://reviews.llvm.org/D115100?vs=394067&id=394690#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115100/new/
https://reviews.llvm.org/D115100
Files:
libcxx/include/__tuple
libcxx/include/type_traits
Index: libcxx/include/type_traits
===================================================================
--- libcxx/include/type_traits
+++ libcxx/include/type_traits
@@ -550,8 +550,6 @@
// is_same
-#if __has_keyword(__is_same)
-
template <class _Tp, class _Up>
struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> { };
@@ -560,36 +558,18 @@
inline constexpr bool is_same_v = __is_same(_Tp, _Up);
#endif
-#else
-
-template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {};
+// _IsSame<T,U> has the same effect as is_same<T,U> but instantiates fewer types:
+// is_same<A,B> and is_same<C,D> are guaranteed to be different types, but
+// _IsSame<A,B> and _IsSame<C,D> are the same type (namely, false_type).
+// Neither GCC nor Clang can mangle the __is_same builtin, so _IsSame
+// mustn't be directly used anywhere that contributes to name-mangling
+// (such as in a dependent return type).
-#if _LIBCPP_STD_VER > 14
template <class _Tp, class _Up>
-inline constexpr bool is_same_v = is_same<_Tp, _Up>::value;
-#endif
-
-#endif // __is_same
+using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
template <class _Tp, class _Up>
-using _IsSame = _BoolConstant<
-#ifdef __clang__
- __is_same(_Tp, _Up)
-#else
- is_same<_Tp, _Up>::value
-#endif
->;
-
-template <class _Tp, class _Up>
-using _IsNotSame = _BoolConstant<
-#ifdef __clang__
- !__is_same(_Tp, _Up)
-#else
- !is_same<_Tp, _Up>::value
-#endif
->;
-
+using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;
template <class _Tp>
using __test_for_primary_template = __enable_if_t<
Index: libcxx/include/__tuple
===================================================================
--- libcxx/include/__tuple
+++ libcxx/include/__tuple
@@ -387,7 +387,7 @@
struct __all_dummy;
template <bool ..._Pred>
-using __all = _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>;
+struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>> {};
struct __tuple_sfinae_base {
template <template <class, class...> class _Trait,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115100.394690.patch
Type: text/x-patch
Size: 2209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211216/40ab8320/attachment.bin>
More information about the libcxx-commits
mailing list