OSDN Git Service

* include/bits/random.tcc (seed_seq::generate): Cast max()
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / bitset
index f880e72..7f3cb4d 100644 (file)
 #include <iosfwd>
 #include <bits/cxxabi_forced.h>
 
-#define _GLIBCXX_BITSET_BITS_PER_WORD  (__CHAR_BIT__ * sizeof(unsigned long))
+#define _GLIBCXX_BITSET_BITS_PER_WORD  (__CHAR_BIT__ * __SIZEOF_LONG__)
 #define _GLIBCXX_BITSET_WORDS(__n) \
   ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
    ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
 
+#define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
@@ -92,19 +94,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 #endif
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichword(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichbyte(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
       { return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
       static _GLIBCXX_CONSTEXPR _WordT
-      _S_maskbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
       _WordT&
@@ -183,15 +185,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        return true;
       }
 
-      size_t
-      _M_are_all_aux() const _GLIBCXX_NOEXCEPT
-      {
-       for (size_t __i = 0; __i < _Nw - 1; __i++)
-         if (_M_w[__i] != ~static_cast<_WordT>(0))
-           return 0;
-       return ((_Nw - 1) * _GLIBCXX_BITSET_BITS_PER_WORD
-               + __builtin_popcountl(_M_hiword()));
-      }
+      template<size_t _Nb>
+        bool
+        _M_are_all() const _GLIBCXX_NOEXCEPT
+        {
+         for (size_t __i = 0; __i < _Nw - 1; __i++)
+           if (_M_w[__i] != ~static_cast<_WordT>(0))
+             return false;
+         return _M_hiword() == (~static_cast<_WordT>(0)
+                                >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
+                                    - _Nb));
+       }
 
       bool
       _M_is_any() const _GLIBCXX_NOEXCEPT
@@ -385,19 +389,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       { }
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichword(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichbyte(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
       {  return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
       static _GLIBCXX_CONSTEXPR _WordT
-      _S_maskbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
       _WordT&
@@ -458,9 +462,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       _M_is_equal(const _Base_bitset<1>& __x) const _GLIBCXX_NOEXCEPT
       { return _M_w == __x._M_w; }
 
-      size_t
-      _M_are_all_aux() const _GLIBCXX_NOEXCEPT
-      { return __builtin_popcountl(_M_w); }
+      template<size_t _Nb>
+        bool
+        _M_are_all() const _GLIBCXX_NOEXCEPT
+        { return _M_w == (~static_cast<_WordT>(0)
+                         >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
 
       bool
       _M_is_any() const _GLIBCXX_NOEXCEPT
@@ -527,19 +533,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       { }
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichword(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichbyte(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
       static _GLIBCXX_CONSTEXPR size_t
-      _S_whichbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
       {  return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
       static _GLIBCXX_CONSTEXPR _WordT
-      _S_maskbit(size_t __pos ) _GLIBCXX_NOEXCEPT
+      _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
       // This would normally give access to the data.  The bounds-checking
@@ -603,9 +609,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       _M_is_equal(const _Base_bitset<0>&) const _GLIBCXX_NOEXCEPT
       { return true; }
 
-      size_t
-      _M_are_all_aux() const _GLIBCXX_NOEXCEPT
-      { return 0; }
+      template<size_t _Nb>
+        bool
+        _M_are_all() const _GLIBCXX_NOEXCEPT
+        { return true; }
 
       bool
       _M_is_any() const _GLIBCXX_NOEXCEPT
@@ -643,22 +650,40 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     {
       typedef unsigned long _WordT;
 
-      static void 
+      static void
       _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
       { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
     };
 
   template<>
     struct _Sanitize<0>
-    { 
+    {
       typedef unsigned long _WordT;
 
-      static void 
+      static void
       _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { } 
     };
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<size_t _Nb, bool = _Nb < _GLIBCXX_BITSET_BITS_PER_ULL>
+    struct _Sanitize_val
+    {
+      static constexpr unsigned long long
+      _S_do_sanitize_val(unsigned long long __val)
+      { return __val; }
+    };
+
+  template<size_t _Nb>
+    struct _Sanitize_val<_Nb, true>
+    {
+      static constexpr unsigned long long
+      _S_do_sanitize_val(unsigned long long __val)
+      { return __val & ~((~static_cast<unsigned long long>(0)) << _Nb); }
+    };
+#endif
+
   /**
-   *  @brief  The %bitset class represents a @e fixed-size sequence of bits.
+   *  The %bitset class represents a @e fixed-size sequence of bits.
    *
    *  @ingroup containers
    *
@@ -822,7 +847,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       /// Initial bits bitwise-copied from a single word (others set to zero).
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
       constexpr bitset(unsigned long long __val) noexcept
-      : _Base(__val) { }
+      : _Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
 #else
       bitset(unsigned long __val)
       : _Base(__val)
@@ -830,11 +855,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 #endif
 
       /**
-       *  @brief  Use a subset of a string.
-       *  @param  s  A string of @a 0 and @a 1 characters.
-       *  @param  position  Index of the first character in @a s to use;
+       *  Use a subset of a string.
+       *  @param  __s  A string of @a 0 and @a 1 characters.
+       *  @param  __position  Index of the first character in @a __s to use;
        *                    defaults to zero.
-       *  @throw  std::out_of_range  If @a pos is bigger the size of @a s.
+       *  @throw  std::out_of_range  If @a pos is bigger the size of @a __s.
        *  @throw  std::invalid_argument  If a character appears in the string
        *                                 which is neither @a 0 nor @a 1.
        */
@@ -853,11 +878,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        }
 
       /**
-       *  @brief  Use a subset of a string.
-       *  @param  s  A string of @a 0 and @a 1 characters.
-       *  @param  position  Index of the first character in @a s to use.
-       *  @param  n    The number of characters to copy.
-       *  @throw  std::out_of_range  If @a pos is bigger the size of @a s.
+       *  Use a subset of a string.
+       *  @param  __s  A string of @a 0 and @a 1 characters.
+       *  @param  __position  Index of the first character in @a __s to use.
+       *  @param  __n    The number of characters to copy.
+       *  @throw std::out_of_range If @a __position is bigger the size
+       *  of @a __s.
        *  @throw  std::invalid_argument  If a character appears in the string
        *                                 which is neither @a 0 nor @a 1.
        */
@@ -888,13 +914,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
       /**
-       *  @brief  Construct from a character %array.
-       *  @param  str  An %array of characters @a zero and @a one.
-       *  @param  n    The number of characters to use.
-       *  @param  zero The character corresponding to the value 0.
-       *  @param  one  The character corresponding to the value 1.
-       *  @throw  std::invalid_argument  If a character appears in the string
-       *                                 which is neither @a zero nor @a one.
+       *  Construct from a character %array.
+       *  @param  __str  An %array of characters @a zero and @a one.
+       *  @param  __n    The number of characters to use.
+       *  @param  __zero The character corresponding to the value 0.
+       *  @param  __one  The character corresponding to the value 1.
+       *  @throw  std::invalid_argument If a character appears in the string
+       *                                which is neither @a __zero nor @a __one.
        */
       template<typename _CharT>
         explicit
@@ -918,8 +944,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       // 23.3.5.2 bitset operations:
       //@{
       /**
-       *  @brief  Operations on bitsets.
-       *  @param  rhs  A same-sized bitset.
+       *  Operations on bitsets.
+       *  @param  __rhs  A same-sized bitset.
        *
        *  These should be self-explanatory.
        */
@@ -947,8 +973,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       
       //@{
       /**
-       *  @brief  Operations on bitsets.
-       *  @param  position  The number of places to shift.
+       *  Operations on bitsets.
+       *  @param  __position  The number of places to shift.
        *
        *  These should be self-explanatory.
        */
@@ -1036,8 +1062,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
       /**
        *  @brief Sets a given bit to a particular value.
-       *  @param  position  The index of the bit.
-       *  @param  val  Either true or false, defaults to true.
+       *  @param  __position  The index of the bit.
+       *  @param  __val  Either true or false, defaults to true.
        *  @throw  std::out_of_range  If @a pos is bigger the size of the %set.
        */
       bitset<_Nb>&
@@ -1060,7 +1086,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
       /**
        *  @brief Sets a given bit to false.
-       *  @param  position  The index of the bit.
+       *  @param  __position  The index of the bit.
        *  @throw  std::out_of_range  If @a pos is bigger the size of the %set.
        *
        *  Same as writing @c set(pos,false).
@@ -1086,7 +1112,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
       /**
        *  @brief Toggles a given bit to its opposite value.
-       *  @param  position  The index of the bit.
+       *  @param  __position  The index of the bit.
        *  @throw  std::out_of_range  If @a pos is bigger the size of the %set.
        */
       bitset<_Nb>&
@@ -1105,7 +1131,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       //@{
       /**
        *  @brief  Array-indexing support.
-       *  @param  position  Index into the %bitset.
+       *  @param  __position  Index into the %bitset.
        *  @return A bool for a <em>const %bitset</em>.  For non-const
        *           bitsets, an instance of the reference proxy class.
        *  @note  These operators do no range checking and throw no exceptions,
@@ -1271,7 +1297,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       
       /**
        *  @brief Tests the value of a bit.
-       *  @param  position  The index of a bit.
+       *  @param  __position  The index of a bit.
        *  @return  The value at @a pos.
        *  @throw  std::out_of_range  If @a pos is bigger the size of the %set.
        */
@@ -1291,7 +1317,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        */
       bool
       all() const _GLIBCXX_NOEXCEPT
-      { return this->_M_are_all_aux() == _Nb; }
+      { return this->template _M_are_all<_Nb>(); }
 
       /**
        *  @brief Tests whether any of the bits are on.
@@ -1333,12 +1359,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       /**
        *  @brief  Finds the index of the next "on" bit after prev.
        *  @return  The index of the next bit set, or size() if not found.
-       *  @param  prev  Where to start searching.
+       *  @param  __prev  Where to start searching.
        *  @ingroup SGIextensions
        *  @sa  _Find_first
        */
       size_t
-      _Find_next(size_t __prev ) const _GLIBCXX_NOEXCEPT
+      _Find_next(size_t __prev) const _GLIBCXX_NOEXCEPT
       { return this->_M_do_find_next(__prev, _Nb); }
     };
 
@@ -1351,7 +1377,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
                       size_t __pos, size_t __n, _CharT __zero, _CharT __one)
       {
        reset();
-       const size_t __nbits = std::min(_Nb, std::min(__n, __len - __pos));
+       const size_t __nbits = std::min(_Nb, std::min(__n, size_t(__len - __pos)));
        for (size_t __i = __nbits; __i > 0; --__i)
          {
            const _CharT __c = __s[__pos + __nbits - __i];
@@ -1381,8 +1407,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   //@{
   /**
    *  @brief  Global bitwise operations on bitsets.
-   *  @param  x  A bitset.
-   *  @param  y  A bitset of the same size as @a x.
+   *  @param  __x  A bitset.
+   *  @param  __y  A bitset of the same size as @a __x.
    *  @return  A new bitset.
    *
    *  These should be self-explanatory.
@@ -1512,6 +1538,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
 
 #undef _GLIBCXX_BITSET_WORDS
 #undef _GLIBCXX_BITSET_BITS_PER_WORD
+#undef _GLIBCXX_BITSET_BITS_PER_ULL
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 
@@ -1528,7 +1555,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
     {
       size_t
-      operator()(const _GLIBCXX_STD_C::bitset<_Nb>& __b) const
+      operator()(const _GLIBCXX_STD_C::bitset<_Nb>& __b) const noexcept
       {
        const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
        return std::_Hash_impl::hash(__b._M_getdata(), __clength);
@@ -1540,7 +1567,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
     {
       size_t
-      operator()(const _GLIBCXX_STD_C::bitset<0>&) const
+      operator()(const _GLIBCXX_STD_C::bitset<0>&) const noexcept
       { return 0; }
     };