|
12 | 12 | #include <algorithm>
|
13 | 13 | #include <cmath>
|
14 | 14 | #include <cstdint>
|
15 |
| -#include <iosfwd> |
| 15 | +#include <ios> |
16 | 16 | #include <vector>
|
17 | 17 | #include <xbit_ops.h>
|
18 | 18 | #include <xstring>
|
@@ -674,6 +674,12 @@ public:
|
674 | 674 | return _Ostr;
|
675 | 675 | }
|
676 | 676 |
|
| 677 | + template <class _Elem, class _Traits> |
| 678 | + basic_ostream<_Elem, _Traits>& _Write_full(basic_ostream<_Elem, _Traits>& _Ostr) const { // write state to _Ostr |
| 679 | + _Swc_Traits::_Write_full(_Ostr, *this, _Carry); |
| 680 | + return _Ostr; |
| 681 | + } |
| 682 | + |
677 | 683 | protected:
|
678 | 684 | template <class _Gen>
|
679 | 685 | void _Seed(_Gen& _Gx, bool _Readcy, true_type) { // reset sequence from numeric value
|
@@ -816,14 +822,24 @@ struct _Swc_traits { // traits for subtract_with_carry generator
|
816 | 822 | int _Kx = _Get_wc();
|
817 | 823 |
|
818 | 824 | for (size_t _Ix = 0; _Ix < _Nw; ++_Ix) {
|
819 |
| - for (int _Jx = 1; _Jx <= _Kx; ++_Jx) { // unpack into _Kx words |
820 |
| - unsigned int _Word = static_cast<unsigned int>(_Buf._At(_Ix) >> ((_Kx - _Jx) * 32)); |
| 825 | + for (int _Jx = 0; _Jx < _Kx; ++_Jx) { // unpack into _Kx words |
| 826 | + const unsigned int _Word = static_cast<unsigned int>(_Buf._At(_Ix) >> (_Jx * 32)); |
821 | 827 | _Ostr << _Word << ' ';
|
822 | 828 | }
|
823 | 829 | }
|
824 | 830 |
|
825 | 831 | _Ostr << _Cy;
|
826 | 832 | }
|
| 833 | + |
| 834 | + template <class _Elem, class _Traits> |
| 835 | + static void _Write_full( |
| 836 | + basic_ostream<_Elem, _Traits>& _Ostr, const _Circ_buf<_Ty, _Nw>& _Buf, _Cy_t _Cy) { // write state to _Ostr |
| 837 | + for (size_t _Ix = 0; _Ix < _Nw; ++_Ix) { |
| 838 | + _Ostr << _Buf._At(_Ix) << ' '; |
| 839 | + } |
| 840 | + |
| 841 | + _Ostr << _Cy; |
| 842 | + } |
827 | 843 | };
|
828 | 844 |
|
829 | 845 | template <class _Ty, _Ty _Mx, size_t _Sx, size_t _Rx>
|
@@ -908,6 +924,44 @@ public:
|
908 | 924 | _NODISCARD static constexpr _Ty(max)() {
|
909 | 925 | return _Mx - 1;
|
910 | 926 | }
|
| 927 | + |
| 928 | + template <class _Elem, class _Traits> |
| 929 | + friend basic_ostream<_Elem, _Traits>& operator<<( |
| 930 | + basic_ostream<_Elem, _Traits>& _Ostr, const subtract_with_carry_engine& _Eng) { |
| 931 | + const auto _Save_flags = _Ostr.flags(ios_base::dec | ios_base::left); |
| 932 | + const auto _Save_fill = _Ostr.fill(' '); |
| 933 | + _Eng._Write_full(_Ostr); |
| 934 | + _Ostr.flags(_Save_flags); |
| 935 | + _Ostr.fill(_Save_fill); |
| 936 | + return _Ostr; |
| 937 | + } |
| 938 | + |
| 939 | + template <class _Elem, class _Traits> |
| 940 | + friend basic_istream<_Elem, _Traits>& operator>>( |
| 941 | + basic_istream<_Elem, _Traits>& _Istr, subtract_with_carry_engine& _Eng) { |
| 942 | + constexpr auto _Nx = long_lag; |
| 943 | + result_type _Buffer[_Nx]; |
| 944 | + typename _Mybase::_Traits::_Cy_t _Carry_buf; |
| 945 | + const auto _Save_flags = _Istr.flags(ios_base::dec | ios_base::skipws); |
| 946 | + for (size_t _Ix = 0; _Ix < _Nx; ++_Ix) { |
| 947 | + _Istr >> _Buffer[_Ix]; |
| 948 | + } |
| 949 | + |
| 950 | + _Istr >> _Carry_buf; |
| 951 | + if (_Istr) { |
| 952 | + for (size_t _Ix = 0; _Ix < _Nx; ++_Ix) { |
| 953 | + _Eng._Ax[_Ix] = _Buffer[_Ix]; |
| 954 | + } |
| 955 | + |
| 956 | + _Eng._Carry = _Carry_buf; |
| 957 | + _Eng._Idx = _Nx; |
| 958 | + } else { |
| 959 | + _Istr.setstate(ios_base::failbit); |
| 960 | + } |
| 961 | + |
| 962 | + _Istr.flags(_Save_flags); |
| 963 | + return _Istr; |
| 964 | + } |
911 | 965 | };
|
912 | 966 |
|
913 | 967 | #if _HAS_TR1_NAMESPACE
|
|
0 commit comments