diff --git a/libcxx/include/bitset b/libcxx/include/bitset --- a/libcxx/include/bitset +++ b/libcxx/include/bitset @@ -122,6 +122,7 @@ #include #include #include +#include #include // standard-mandated includes @@ -691,18 +692,31 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} - template::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 - explicit bitset(const _CharT* __str, - typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, - _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 - explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, - typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, - typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = - (basic_string<_CharT,_Traits,_Allocator>::npos), - _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); + template ::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset( + const _CharT* __str, + typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, + _CharT __zero = _CharT('0'), + _CharT __one = _CharT('1')) { + + size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str)); + __init(basic_string_view<_CharT>(__str, __rlen), __zero, __one); + } + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset( + const basic_string<_CharT, _Traits, _Allocator>& __str, + typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0, + typename basic_string<_CharT, _Traits, _Allocator>::size_type __n = + (basic_string<_CharT, _Traits, _Allocator>::npos), + _CharT __zero = _CharT('0'), + _CharT __one = _CharT('1')) { + + if (__pos > __str.size()) + std::__throw_out_of_range("bitset string pos out of range"); + + size_t __rlen = std::min(__n, __str.size() - __pos); + __init(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one); + } // 23.3.5.2 bitset operations: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 @@ -778,6 +792,22 @@ bitset operator>>(size_t __pos) const _NOEXCEPT; private: + template + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void + __init(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) { + + for (size_t __i = 0; __i < __str.size(); ++__i) + if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) + std::__throw_invalid_argument("bitset string ctor has invalid argument"); + + size_t __mp = std::min(__str.size(), _Size); + size_t __i = 0; + for (; __i < __mp; ++__i) { + _CharT __c = __str[__mp - 1 - __i]; + (*this)[__i] = _Traits::eq(__c, __one); + } + std::fill(base::__make_iter(__i), base::__make_iter(_Size), false); + } _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} @@ -785,54 +815,6 @@ friend struct hash; }; -template -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 -bitset<_Size>::bitset(const _CharT* __str, - typename basic_string<_CharT>::size_type __n, - _CharT __zero, _CharT __one) -{ - size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); - for (size_t __i = 0; __i < __rlen; ++__i) - if (__str[__i] != __zero && __str[__i] != __one) - __throw_invalid_argument("bitset string ctor has invalid argument"); - - size_t __mp = _VSTD::min(__rlen, _Size); - size_t __i = 0; - for (; __i < __mp; ++__i) - { - _CharT __c = __str[__mp - 1 - __i]; - (*this)[__i] = (__c == __one); - } - _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); -} - -template -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 -bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, - typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, - typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, - _CharT __zero, _CharT __one) -{ - if (__pos > __str.size()) - __throw_out_of_range("bitset string pos out of range"); - - size_t __rlen = _VSTD::min(__n, __str.size() - __pos); - for (size_t __i = __pos; __i < __pos + __rlen; ++__i) - if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) - __throw_invalid_argument("bitset string ctor has invalid argument"); - - size_t __mp = _VSTD::min(__rlen, _Size); - size_t __i = 0; - for (; __i < __mp; ++__i) - { - _CharT __c = __str[__pos + __mp - 1 - __i]; - (*this)[__i] = _Traits::eq(__c, __one); - } - _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); -} - template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv --- a/libcxx/test/libcxx/transitive_includes/cxx03.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv @@ -97,6 +97,7 @@ bitset new bitset stdexcept bitset string +bitset string_view bitset type_traits bitset version ccomplex complex diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv --- a/libcxx/test/libcxx/transitive_includes/cxx11.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv @@ -97,6 +97,7 @@ bitset new bitset stdexcept bitset string +bitset string_view bitset type_traits bitset version ccomplex complex diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv --- a/libcxx/test/libcxx/transitive_includes/cxx14.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv @@ -97,6 +97,7 @@ bitset new bitset stdexcept bitset string +bitset string_view bitset type_traits bitset version ccomplex complex diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv --- a/libcxx/test/libcxx/transitive_includes/cxx17.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv @@ -97,6 +97,7 @@ bitset new bitset stdexcept bitset string +bitset string_view bitset type_traits bitset version ccomplex complex diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv --- a/libcxx/test/libcxx/transitive_includes/cxx20.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv @@ -96,6 +96,7 @@ bitset new bitset stdexcept bitset string +bitset string_view bitset type_traits bitset version ccomplex complex diff --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv --- a/libcxx/test/libcxx/transitive_includes/cxx23.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv @@ -57,6 +57,7 @@ bitset new bitset stdexcept bitset string +bitset string_view bitset version ccomplex complex charconv cerrno diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv --- a/libcxx/test/libcxx/transitive_includes/cxx26.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv @@ -57,6 +57,7 @@ bitset new bitset stdexcept bitset string +bitset string_view bitset version ccomplex complex charconv cerrno