public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-2883] libstdc++: Use new built-ins for std::is_convertible traits
@ 2022-09-26 22:48 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2022-09-26 22:48 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:af85ad891703db220b25e7847f10d0bbec4becf4

commit r13-2883-gaf85ad891703db220b25e7847f10d0bbec4becf4
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Sep 23 23:21:11 2022 +0100

    libstdc++: Use new built-ins for std::is_convertible traits
    
    libstdc++-v3/ChangeLog:
    
            * include/std/type_traits (is_convertible, is_convertible_v):
            Define using new built-in.
            (is_nothrow_convertible is_nothrow_convertible_v): Likewise.

Diff:
---
 libstdc++-v3/include/std/type_traits | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index c5853fcad90..1ac805152d4 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1381,6 +1381,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : public integral_constant<bool, __is_base_of(_Base, _Derived)>
     { };
 
+#if __has_builtin(__is_convertible)
+  template<typename _From, typename _To>
+    struct is_convertible
+    : public __bool_constant<__is_convertible(_From, _To)>
+    { };
+#else
   template<typename _From, typename _To,
            bool = __or_<is_void<_From>, is_function<_To>,
                         is_array<_To>>::value>
@@ -1416,12 +1422,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_convertible
     : public __is_convertible_helper<_From, _To>::type
     { };
+#endif
 
   // helper trait for unique_ptr<T[]>, shared_ptr<T[]>, and span<T, N>
   template<typename _ToElementType, typename _FromElementType>
     using __is_array_convertible
       = is_convertible<_FromElementType(*)[], _ToElementType(*)[]>;
 
+#if __cplusplus >= 202002L
+#define __cpp_lib_is_nothrow_convertible 201806L
+
+#if __has_builtin(__is_nothrow_convertible)
+  /// is_nothrow_convertible_v
+  template<typename _From, typename _To>
+    inline constexpr bool is_nothrow_convertible_v
+      = __is_nothrow_convertible(_From, _To);
+
+  /// is_nothrow_convertible
+  template<typename _From, typename _To>
+    struct is_nothrow_convertible
+    : public bool_constant<is_nothrow_convertible_v<_From, _To>>
+    { };
+#else
   template<typename _From, typename _To,
            bool = __or_<is_void<_From>, is_function<_To>,
                         is_array<_To>>::value>
@@ -1451,8 +1473,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     };
 #pragma GCC diagnostic pop
 
-#if __cplusplus > 201703L
-#define __cpp_lib_is_nothrow_convertible 201806L
   /// is_nothrow_convertible
   template<typename _From, typename _To>
     struct is_nothrow_convertible
@@ -1463,6 +1483,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _From, typename _To>
     inline constexpr bool is_nothrow_convertible_v
       = is_nothrow_convertible<_From, _To>::value;
+#endif
 #endif // C++2a
 
   // Const-volatile modifications.
@@ -3265,7 +3286,7 @@ template <typename _Tp>
 template <typename _Base, typename _Derived>
   inline constexpr bool is_base_of_v = __is_base_of(_Base, _Derived);
 template <typename _From, typename _To>
-  inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
+  inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
 template<typename _Fn, typename... _Args>
   inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
 template<typename _Fn, typename... _Args>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-26 22:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 22:48 [gcc r13-2883] libstdc++: Use new built-ins for std::is_convertible traits Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).