[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
Mon Dec 6 08:11:42 PST 2021
Quuxplusone updated this revision to Diff 392072.
Quuxplusone edited the summary of this revision.
Quuxplusone added a comment.
Remove the `#if` entirely.
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,17 @@
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 {};
-
-#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
+// _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).
+// If we ever need to support a compiler without the __is_same builtin,
+// we can make this an alias template for `is_same<T,U>::type`.
template <class _Tp, class _Up>
-using _IsSame = _BoolConstant<
-#ifdef __clang__
- __is_same(_Tp, _Up)
-#else
- is_same<_Tp, _Up>::value
-#endif
->;
+using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
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<
@@ -600,10 +579,6 @@
__test_for_primary_template, _Tp
>;
-struct __two {char __lx[2];};
-
-// helper class:
-
// is_const
#if __has_keyword(__is_const)
@@ -958,6 +933,8 @@
// is_class
+struct __two {char __lx[2];};
+
#if __has_feature(is_class) || defined(_LIBCPP_COMPILER_GCC)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
Index: libcxx/include/tuple
===================================================================
--- libcxx/include/tuple
+++ libcxx/include/tuple
@@ -1116,13 +1116,12 @@
tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
#endif
+template <class ..._Ts>
+struct __all_are_swappable : __all<__is_swappable<_Ts>::value...> {};
+
template <class ..._Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-typename enable_if
-<
- __all<__is_swappable<_Tp>::value...>::value,
- void
->::type
+typename enable_if<__all_are_swappable<_Tp...>::value>::type
swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
_NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
{__t.swap(__u);}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115100.392072.patch
Type: text/x-patch
Size: 2778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211206/9b93f870/attachment.bin>
More information about the libcxx-commits
mailing list