Skip to content

Commit 509e87c

Browse files
committed
Simplify bitset::{any, all}
1 parent 3c90c90 commit 509e87c

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;
@@ -713,8 +683,8 @@ public:
713683
_LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
714684
# endif
715685
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;
716-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
717-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
686+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return __base::all(); }
687+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return __base::any(); }
718688
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }
719689
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;
720690
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;
@@ -901,16 +871,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(siz
901871
return (*this)[__pos];
902872
}
903873

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

0 commit comments

Comments
 (0)