File tree 1 file changed +11
-6
lines changed 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -40,8 +40,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_popcount(unsigned lo
40
40
}
41
41
42
42
template <class _Tp >
43
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount (_Tp __t ) _NOEXCEPT {
44
- static_assert (is_unsigned<_Tp>::value, " __popcount only works with unsigned types" );
43
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount_impl (_Tp __t ) _NOEXCEPT {
45
44
if _LIBCPP_CONSTEXPR (sizeof (_Tp) <= sizeof (unsigned int )) {
46
45
return std::__libcpp_popcount (static_cast <unsigned int >(__t ));
47
46
} else if _LIBCPP_CONSTEXPR (sizeof (_Tp) <= sizeof (unsigned long )) {
@@ -64,15 +63,21 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT {
64
63
}
65
64
}
66
65
66
+ template <class _Tp >
67
+ [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount (_Tp __t ) _NOEXCEPT {
68
+ static_assert (is_unsigned<_Tp>::value, " __popcount only works with unsigned types" );
69
+ #if __has_builtin(__builtin_popcountg) // TODO (LLVM 21): This can be dropped once we only support Clang >= 19.
70
+ return __builtin_popcountg (__t );
71
+ #else
72
+ return std::__popcount_impl (__t );
73
+ #endif
74
+ }
75
+
67
76
#if _LIBCPP_STD_VER >= 20
68
77
69
78
template <__libcpp_unsigned_integer _Tp>
70
79
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr int popcount (_Tp __t ) noexcept {
71
- # if __has_builtin(__builtin_popcountg) // TODO (LLVM 21): This can be dropped once we only support Clang >= 19.
72
- return __builtin_popcountg (__t );
73
- # else
74
80
return std::__popcount (__t );
75
- # endif
76
81
}
77
82
78
83
#endif
You can’t perform that action at this time.
0 commit comments