Skip to content

Commit 30e237c

Browse files
committed
Simplify bitset::{any, all}
1 parent 4d928d5 commit 30e237c

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

libcxx/include/bitset

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

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

230234
private:
@@ -389,40 +393,6 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
389393
return __r;
390394
}
391395

392-
template <size_t _N_words, size_t _Size>
393-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
394-
// do middle whole words
395-
size_t __n = _Size;
396-
__const_storage_pointer __p = __first_;
397-
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
398-
if (~*__p)
399-
return false;
400-
// do last partial word
401-
if (__n > 0) {
402-
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
403-
if (~*__p & __m)
404-
return false;
405-
}
406-
return true;
407-
}
408-
409-
template <size_t _N_words, size_t _Size>
410-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
411-
// do middle whole words
412-
size_t __n = _Size;
413-
__const_storage_pointer __p = __first_;
414-
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
415-
if (*__p)
416-
return true;
417-
// do last partial word
418-
if (__n > 0) {
419-
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
420-
if (*__p & __m)
421-
return true;
422-
}
423-
return false;
424-
}
425-
426396
template <size_t _N_words, size_t _Size>
427397
inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
428398
size_t __h = 0;

0 commit comments

Comments
 (0)