[libcxx-commits] [libcxx] [libc++] Use variable templates in is_floating_point (PR #167141)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Nov 8 05:41:27 PST 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/167141
None
>From ea660188d85d6c7feaa9dad9ddc75e37194f52ed Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 8 Nov 2025 14:41:07 +0100
Subject: [PATCH] [libc++] Use variable templates in is_floating_point
---
libcxx/include/__type_traits/is_floating_point.h | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/libcxx/include/__type_traits/is_floating_point.h b/libcxx/include/__type_traits/is_floating_point.h
index b87363fe5b357..17e6e0281a687 100644
--- a/libcxx/include/__type_traits/is_floating_point.h
+++ b/libcxx/include/__type_traits/is_floating_point.h
@@ -20,18 +20,19 @@
_LIBCPP_BEGIN_NAMESPACE_STD
// clang-format off
-template <class _Tp> struct __libcpp_is_floating_point : false_type {};
-template <> struct __libcpp_is_floating_point<float> : true_type {};
-template <> struct __libcpp_is_floating_point<double> : true_type {};
-template <> struct __libcpp_is_floating_point<long double> : true_type {};
+template <class _Tp> inline const bool __is_floating_point_impl = false;
+template <> inline const bool __is_floating_point_impl<float> = true;
+template <> inline const bool __is_floating_point_impl<double> = true;
+template <> inline const bool __is_floating_point_impl<long double> = true;
// clang-format on
template <class _Tp>
-struct _LIBCPP_NO_SPECIALIZATIONS is_floating_point : __libcpp_is_floating_point<__remove_cv_t<_Tp> > {};
+struct _LIBCPP_NO_SPECIALIZATIONS is_floating_point
+ : integral_constant<bool, __is_floating_point_impl<__remove_cv_t<_Tp> > > {};
#if _LIBCPP_STD_VER >= 17
-template <class _Tp>
-_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value;
+template<class _Tp>
+inline constexpr bool is_floating_point_v = __is_floating_point_impl<__remove_cv_t<_Tp>>;
#endif
_LIBCPP_END_NAMESPACE_STD
More information about the libcxx-commits
mailing list