diff options
author | kan <kan@FreeBSD.org> | 2003-07-11 03:42:04 +0000 |
---|---|---|
committer | kan <kan@FreeBSD.org> | 2003-07-11 03:42:04 +0000 |
commit | c7bbbdd036d3dd7ae253fb13c9994215af06f073 (patch) | |
tree | ce14546aca3a67fa3440aed52f132bafaf68fe70 /contrib/libstdc++/include/std/std_bitset.h | |
parent | b2a8872fbe1ec1c49094559ac7b78e6ea4ab7180 (diff) | |
download | FreeBSD-src-c7bbbdd036d3dd7ae253fb13c9994215af06f073.zip FreeBSD-src-c7bbbdd036d3dd7ae253fb13c9994215af06f073.tar.gz |
Gcc 3.3.1-pre 2003-07-11 C++ support bits.
Diffstat (limited to 'contrib/libstdc++/include/std/std_bitset.h')
-rw-r--r-- | contrib/libstdc++/include/std/std_bitset.h | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/contrib/libstdc++/include/std/std_bitset.h b/contrib/libstdc++/include/std/std_bitset.h index fe60b01..ebe1650 100644 --- a/contrib/libstdc++/include/std/std_bitset.h +++ b/contrib/libstdc++/include/std/std_bitset.h @@ -219,7 +219,7 @@ namespace std void _Base_bitset<_Nw>::_M_do_left_shift(size_t __shift) { - if (__shift != 0) + if (__builtin_expect(__shift != 0, 1)) { const size_t __wshift = __shift / _GLIBCPP_BITSET_BITS_PER_WORD; const size_t __offset = __shift % _GLIBCPP_BITSET_BITS_PER_WORD; @@ -244,7 +244,7 @@ namespace std void _Base_bitset<_Nw>::_M_do_right_shift(size_t __shift) { - if (__shift != 0) + if (__builtin_expect(__shift != 0, 1)) { const size_t __wshift = __shift / _GLIBCPP_BITSET_BITS_PER_WORD; const size_t __offset = __shift % _GLIBCPP_BITSET_BITS_PER_WORD; @@ -570,6 +570,7 @@ namespace std struct _Sanitize<0> { static void _S_do_sanitize(unsigned long) { } }; + /** * @brief The %bitset class represents a @e fixed-size sequence of bits. * @@ -578,17 +579,19 @@ namespace std * (Note that %bitset does @e not meet the formal requirements of a * <a href="tables.html#65">container</a>. Mainly, it lacks iterators.) * - * The template argument, @a _Nb, may be any nonzero number of type - * size_t. + * The template argument, @a Nb, may be any non-negative number, + * specifying the number of bits (e.g., "0", "12", "1024*1024"). * - * A %bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused - * bits. (They are the high-order bits in the highest word.) It is - * a class invariant that those unused bits are always zero. + * In the general unoptimized case, storage is allocated in word-sized + * blocks. Let B be the number of bits in a word, then (Nb+(B-1))/B + * words will be used for storage. B - Nb%B bits are unused. (They are + * the high-order bits in the highest word.) It is a class invariant + * that those unused bits are always zero. * * If you think of %bitset as "a simple array of bits," be aware that * your mental picture is reversed: a %bitset behaves the same way as * bits in integers do, with the bit at index 0 in the "least significant - * / right-hand" position, and the bit at index N-1 in the "most + * / right-hand" position, and the bit at index Nb-1 in the "most * significant / left-hand" position. Thus, unlike other containers, a * %bitset's index "counts from right to left," to put it very loosely. * @@ -619,6 +622,7 @@ namespace std * @endcode * * Also see http://gcc.gnu.org/onlinedocs/libstdc++/ext/sgiexts.html#ch23 + * for a description of extensions. * * @if maint * Most of the actual code isn't contained in %bitset<> itself, but in the @@ -805,16 +809,26 @@ namespace std bitset<_Nb>& operator<<=(size_t __pos) { - this->_M_do_left_shift(__pos); - this->_M_do_sanitize(); + if (__builtin_expect(__pos < _Nb, 1)) + { + this->_M_do_left_shift(__pos); + this->_M_do_sanitize(); + } + else + this->_M_do_reset(); return *this; } bitset<_Nb>& operator>>=(size_t __pos) { - this->_M_do_right_shift(__pos); - this->_M_do_sanitize(); + if (__builtin_expect(__pos < _Nb, 1)) + { + this->_M_do_right_shift(__pos); + this->_M_do_sanitize(); + } + else + this->_M_do_reset(); return *this; } //@} @@ -1183,6 +1197,7 @@ namespace std typename basic_istream<_CharT, _Traits>::sentry __sentry(__is); if (__sentry) { + ios_base::iostate __state = ios_base::goodbit; basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf(); for (size_t __i = 0; __i < _Nb; ++__i) { @@ -1191,7 +1206,7 @@ namespace std typename _Traits::int_type __c1 = __buf->sbumpc(); if (_Traits::eq_int_type(__c1, __eof)) { - __is.setstate(ios_base::eofbit); + __state |= ios_base::eofbit; break; } else @@ -1201,19 +1216,21 @@ namespace std if (__c == '0' || __c == '1') __tmp.push_back(__c); - else if (_Traits::eq_int_type(__buf->sputbackc(__c2), - __eof)) + else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) { - __is.setstate(ios_base::failbit); + __state |= ios_base::failbit; break; } } } if (__tmp.empty() && !_Nb) - __is.setstate(ios_base::failbit); + __state |= ios_base::failbit; else __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb); + + if (__state != ios_base::goodbit) + __is.setstate(__state); // may throw an exception } return __is; |