[libcxx-commits] [libcxx] [libc++] Simplify the implementation of remove_reference (PR #85207)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 14 04:30:47 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
GCC 13 introduced the type trait `__remove_reference`. We can simplify the implementation of `remove_reference` a bit by using it.
---
Full diff: https://github.com/llvm/llvm-project/pull/85207.diff
1 Files Affected:
- (modified) libcxx/include/__type_traits/remove_reference.h (+7-7)
``````````diff
diff --git a/libcxx/include/__type_traits/remove_reference.h b/libcxx/include/__type_traits/remove_reference.h
index fd66417bd84fed..ba67891758adce 100644
--- a/libcxx/include/__type_traits/remove_reference.h
+++ b/libcxx/include/__type_traits/remove_reference.h
@@ -10,7 +10,6 @@
#define _LIBCPP___TYPE_TRAITS_REMOVE_REFERENCE_H
#include <__config>
-#include <cstddef>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -26,15 +25,16 @@ struct remove_reference {
template <class _Tp>
using __libcpp_remove_reference_t = __remove_reference_t(_Tp);
-#else
-// clang-format off
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG _Tp type;};
-// clang-format on
+#elif __has_builtin(__remove_reference)
+template <class _Tp>
+struct remove_reference {
+ using type _LIBCPP_NODEBUG = __remove_reference(_Tp);
+};
template <class _Tp>
using __libcpp_remove_reference_t = typename remove_reference<_Tp>::type;
+#else
+# error "remove_reference not implemented!"
#endif // __has_builtin(__remove_reference_t)
#if _LIBCPP_STD_VER >= 14
``````````
</details>
https://github.com/llvm/llvm-project/pull/85207
More information about the libcxx-commits
mailing list