[libcxx-commits] [libcxx] [libc++] Simplify the implementation of remove_reference (PR #85207)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 14 04:30:15 PDT 2024
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/85207
GCC 13 introduced the type trait `__remove_reference`. We can simplify the implementation of `remove_reference` a bit by using it.
>From 4ada903a3f05efe3ba0ffe6fa13cabf6db065894 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 14 Mar 2024 12:29:00 +0100
Subject: [PATCH] [libc++] Simplify the implementation of remove_reference
---
libcxx/include/__type_traits/remove_reference.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
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
More information about the libcxx-commits
mailing list