Skip to content

Commit 5b6f12d

Browse files
committed
Simplify bitset::{any, all}
1 parent 252ba8e commit 5b6f12d

File tree

1 file changed

+8
-48
lines changed

1 file changed

+8
-48
lines changed

libcxx/include/bitset

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,12 @@ protected:
224224
return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
225225
}
226226

227-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
228-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
227+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT {
228+
return std::find(__make_iter(0), __make_iter(_Size), false) == __make_iter(_Size);
229+
}
230+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT {
231+
return std::find(__make_iter(0), __make_iter(_Size), true) != __make_iter(_Size);
232+
}
229233
_LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
230234

231235
private:
@@ -388,40 +392,6 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
388392
return __r;
389393
}
390394

391-
template <size_t _N_words, size_t _Size>
392-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
393-
// do middle whole words
394-
size_t __n = _Size;
395-
__const_storage_pointer __p = __first_;
396-
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
397-
if (~*__p)
398-
return false;
399-
// do last partial word
400-
if (__n > 0) {
401-
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
402-
if (~*__p & __m)
403-
return false;
404-
}
405-
return true;
406-
}
407-
408-
template <size_t _N_words, size_t _Size>
409-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
410-
// do middle whole words
411-
size_t __n = _Size;
412-
__const_storage_pointer __p = __first_;
413-
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
414-
if (*__p)
415-
return true;
416-
// do last partial word
417-
if (__n > 0) {
418-
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
419-
if (*__p & __m)
420-
return true;
421-
}
422-
return false;
423-
}
424-
425395
template <size_t _N_words, size_t _Size>
426396
inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
427397
size_t __h = 0;
@@ -716,8 +686,8 @@ public:
716686
_LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
717687
# endif
718688
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;
719-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
720-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
689+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return __base::all(); }
690+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return __base::any(); }
721691
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }
722692
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;
723693
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;
@@ -903,16 +873,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(siz
903873
return (*this)[__pos];
904874
}
905875

906-
template <size_t _Size>
907-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT {
908-
return __base::all();
909-
}
910-
911-
template <size_t _Size>
912-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT {
913-
return __base::any();
914-
}
915-
916876
template <size_t _Size>
917877
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
918878
bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {

0 commit comments

Comments
 (0)