* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
- */
+ */
#ifndef __SGI_STL_BITSET
#define __SGI_STL_BITSET
// THIS FEATURE*. It is experimental, and it may be removed in
// future releases.
-// A bitset of size N, using words of type _WordT, will have
+// A bitset of size N, using words of type _WordT, will have
// N % (sizeof(_WordT) * CHAR_BIT) unused bits. (They are the high-
// order bits in the highest word.) It is a class invariant
// of class bitset<> that those unused bits are always zero.
-// Most of the actual code isn't contained in bitset<> itself, but in the
+// Most of the actual code isn't contained in bitset<> itself, but in the
// base class _Base_bitset. The base class works with whole words, not with
// individual bits. This allows us to specialize _Base_bitset for the
// important special case where the bitset is only a single word.
#endif
// structure to aid in counting bits
-template<bool __dummy>
+template<bool __dummy>
struct _Bit_count {
static unsigned char _S_bit_count[256];
};
// Mapping from 8 bit unsigned integers to the index of the first one
// bit:
-template<bool __dummy>
+template<bool __dummy>
struct _First_one {
static unsigned char _S_first_one[256];
};
return __result;
}
- unsigned long _M_do_to_ulong() const;
+ unsigned long _M_do_to_ulong() const;
// find first "on" bit
size_t _M_do_find_first(size_t __not_found) const;
//
// Definitions of non-inline functions from _Base_bitset.
-//
+//
template<size_t _Nw, class _WordT>
_Base_bitset<_Nw, _WordT>::_Base_bitset(unsigned long __val)
}
template<size_t _Nw, class _WordT>
-void _Base_bitset<_Nw, _WordT>::_M_do_left_shift(size_t __shift)
+void _Base_bitset<_Nw, _WordT>::_M_do_left_shift(size_t __shift)
{
if (__shift != 0) {
const size_t __wshift = __shift / __BITS_PER_WORDT(_WordT);
const size_t __sub_offset = __BITS_PER_WORDT(_WordT) - __offset;
size_t __n = _Nw - 1;
for ( ; __n > __wshift; --__n)
- _M_w[__n] = (_M_w[__n - __wshift] << __offset) |
+ _M_w[__n] = (_M_w[__n - __wshift] << __offset) |
(_M_w[__n - __wshift - 1] >> __sub_offset);
if (__n == __wshift)
_M_w[__n] = _M_w[0] << __offset;
}
template<size_t _Nw, class _WordT>
-void _Base_bitset<_Nw, _WordT>::_M_do_right_shift(size_t __shift)
+void _Base_bitset<_Nw, _WordT>::_M_do_right_shift(size_t __shift)
{
if (__shift != 0) {
const size_t __wshift = __shift / __BITS_PER_WORDT(_WordT);
const size_t __limit = _Nw - __wshift - 1;
size_t __n = 0;
for ( ; __n < __limit; ++__n)
- _M_w[__n] = (_M_w[__n + __wshift] >> __offset) |
+ _M_w[__n] = (_M_w[__n + __wshift] >> __offset) |
(_M_w[__n + __wshift + 1] << __sub_offset);
_M_w[__limit] = _M_w[_Nw-1] >> __offset;
for (size_t __n1 = __limit + 1; __n1 < _Nw; ++__n1)
const overflow_error __overflow("bitset");
if (sizeof(_WordT) >= sizeof(unsigned long)) {
- for (size_t __i = 1; __i < _Nw; ++__i)
- if (_M_w[__i])
+ for (size_t __i = 1; __i < _Nw; ++__i)
+ if (_M_w[__i])
__STL_THROW(__overflow);
const _WordT __mask = static_cast<_WordT>(static_cast<unsigned long>(-1));
- if (_M_w[0] & ~__mask)
+ if (_M_w[0] & ~__mask)
__STL_THROW(__overflow);
return static_cast<unsigned long>(_M_w[0] & __mask);
size_t __min_nwords = __nwords;
if (_Nw > __nwords) {
- for (size_t __i = __nwords; __i < _Nw; ++__i)
- if (_M_w[__i])
+ for (size_t __i = __nwords; __i < _Nw; ++__i)
+ if (_M_w[__i])
__STL_THROW(__overflow);
}
- else
+ else
__min_nwords = _Nw;
-
+
// If unsigned long is 8 bytes and _WordT is 6 bytes, then an unsigned
// long consists of all of one word plus 2 bytes from another word.
const size_t __part = sizeof(unsigned long) % sizeof(_WordT);
- if (__part != 0 && __nwords <= _Nw &&
+ if (__part != 0 && __nwords <= _Nw &&
(_M_w[__min_nwords - 1] >> ((sizeof(_WordT) - __part) * CHAR_BIT)) != 0)
__STL_THROW(__overflow);
} // End _M_do_to_ulong
template<size_t _Nw, class _WordT>
-size_t _Base_bitset<_Nw, _WordT>::_M_do_find_first(size_t __not_found) const
+size_t _Base_bitset<_Nw, _WordT>::_M_do_find_first(size_t __not_found) const
{
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_WordT __thisword = _M_w[__i];
template<size_t _Nw, class _WordT>
size_t
-_Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev,
+_Base_bitset<_Nw, _WordT>::_M_do_find_next(size_t __prev,
size_t __not_found) const
{
// make bound inclusive
_Base_bitset( void ) { _M_do_reset(); }
- _Base_bitset(unsigned long __val);
+ _Base_bitset(unsigned long __val);
static size_t _S_whichword( size_t __pos ) {
return __pos / __BITS_PER_WORDT(_WordT);
return static_cast<unsigned long>(_M_w);
else {
const _WordT __mask = static_cast<_WordT>(static_cast<unsigned long>(-1));
- if (_M_w & ~__mask)
+ if (_M_w & ~__mask)
__STL_THROW(overflow_error("bitset"));
return static_cast<unsigned long>(_M_w);
}
size_t _M_do_find_first(size_t __not_found) const;
// find the next "on" bit that follows "prev"
- size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
+ size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
};
//
template <class _WordT>
-_Base_bitset<1, _WordT>::_Base_bitset(unsigned long __val)
+_Base_bitset<1, _WordT>::_Base_bitset(unsigned long __val)
{
_M_do_reset();
const size_t __n = min(sizeof(unsigned long)*CHAR_BIT,
}
template <class _WordT>
-size_t
-_Base_bitset<1, _WordT>::_M_do_find_next(size_t __prev,
+size_t
+_Base_bitset<1, _WordT>::_M_do_find_next(size_t __prev,
size_t __not_found ) const
{
// make bound inclusive
//
// One last specialization: _M_do_to_ulong() and the constructor from
-// unsigned long are very simple if the bitset consists of a single
+// unsigned long are very simple if the bitset consists of a single
// word of type unsigned long.
//
template<>
-inline unsigned long
+inline unsigned long
_Base_bitset<1, unsigned long>::_M_do_to_ulong() const { return _M_w; }
template<>
// Type _WordT may be any unsigned integral type.
template<size_t _Nb, class _WordT = unsigned long>
-class bitset : private _Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT>
+class bitset : private _Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT>
{
private:
typedef _Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT> _Base;
// 23.3.5.1 constructors:
bitset() {}
- bitset(unsigned long __val) :
+ bitset(unsigned long __val) :
_Base_bitset<__BITSET_WORDS(_Nb,_WordT), _WordT>(__val) {}
template<class _CharT, class _Traits, class _Alloc>
explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s,
size_t __pos = 0,
- size_t __n = size_t(basic_string<_CharT,_Traits,_Alloc>::npos))
- : _Base()
+ size_t __n = basic_string<_CharT,_Traits,_Alloc>::npos)
+ : _Base()
{
- if (__pos > __s.size())
+ if (__pos > __s.size())
__STL_THROW(out_of_range("bitset"));
_M_copy_from_string(__s, __pos, __n);
}
return _Unchecked_flip(__pos);
}
- bitset<_Nb,_WordT> operator~() const {
+ bitset<_Nb,_WordT> operator~() const {
return bitset<_Nb,_WordT>(*this).flip();
}
unsigned long to_ulong() const { return _M_do_to_ulong(); }
-#ifdef __STL_EXPLICIT_FUNCTION_TMPL_ARGS
+#if __STL_EXPLICIT_FUNCTION_TMPL_ARGS
template <class _CharT, class _Traits, class _Alloc>
basic_string<_CharT, _Traits, _Alloc> to_string() const {
basic_string<_CharT, _Traits, _Alloc> __result;
// EXTENSIONS: bit-find operations. These operations are
// experimental, and are subject to change or removal in future
// versions.
- //
+ //
// find the index of the first "on" bit
- size_t _Find_first() const
+ size_t _Find_first() const
{ return _M_do_find_first(_Nb); }
// find the index of the next "on" bit after prev
- size_t _Find_next( size_t __prev ) const
+ size_t _Find_next( size_t __prev ) const
{ return _M_do_find_next(__prev, _Nb); }
};
::_M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
{
__s.assign(_Nb, '0');
-
- for (size_t __i = 0; __i < _Nb; ++__i)
+
+ for (size_t __i = 0; __i < _Nb; ++__i)
if (_Unchecked_test(__i))
__s[_Nb - 1 - __i] = '1';
}
// In new templatized iostreams, use istream::sentry
if (__is.flags() & ios::skipws) {
char __c;
- do
+ do
__is.get(__c);
while (__is && isspace(__c));
if (__is)
__tmp.push_back(__c);
}
- if (__tmp.empty())
+ if (__tmp.empty())
__is.clear(__is.rdstate() | ios::failbit);
else
__x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb);
// Local Variables:
// mode:C++
// End:
-