public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2883] libstdc++: Use new built-ins for std::is_convertible traits Date: Mon, 26 Sep 2022 22:48:25 +0000 (GMT) [thread overview] Message-ID: <20220926224825.DB6543858C83@sourceware.org> (raw) 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>
reply other threads:[~2022-09-26 22:48 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220926224825.DB6543858C83@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).