File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ _LIBCPP_PUSH_MACROS
21
21
22
22
_LIBCPP_BEGIN_NAMESPACE_STD
23
23
24
+ static_assert (__is_unsigned_integer_v<unsigned _BitInt (10 )>);
25
+
24
26
template <class _Tp >
25
27
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount (_Tp __t ) _NOEXCEPT {
26
28
static_assert (__is_unsigned_integer_v<_Tp>, " __popcount only works with unsigned types" );
Original file line number Diff line number Diff line change @@ -867,7 +867,16 @@ bitset<_Size>::to_string(char __zero, char __one) const {
867
867
868
868
template <size_t _Size>
869
869
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT {
870
- return static_cast <size_t >(std::count (__base::__make_iter (0 ), __base::__make_iter (_Size), true ));
870
+ # if defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
871
+ if constexpr (_Size == 0 ) {
872
+ return 0 ;
873
+ } else if constexpr (_Size <= __base::__bits_per_word) {
874
+ return __builtin_popcountg (static_cast <unsigned _BitInt (_Size)>(__base::__first_));
875
+ } else
876
+ # endif
877
+ {
878
+ return static_cast <size_t >(std::count (__base::__make_iter (0 ), __base::__make_iter (_Size), true ));
879
+ }
871
880
}
872
881
873
882
template <size_t _Size>
You can’t perform that action at this time.
0 commit comments