OSDN Git Service

* include/bits/random.tcc (seed_seq::generate): Cast max()
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / bitset
index 7372639..7f3cb4d 100644 (file)
@@ -1,6 +1,7 @@
 // <bitset> -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+// 2011
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 
 #pragma GCC system_header
 
-#include <cstddef>     // For size_t
 #include <string>
 #include <bits/functexcept.h>   // For invalid_argument, out_of_range,
                                 // overflow_error
 #include <iosfwd>
-#include <cxxabi-forced.h>
+#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) < 1 ? 0 : ((__n) + _GLIBCXX_BITSET_BITS_PER_WORD - 1) \
-                  / _GLIBCXX_BITSET_BITS_PER_WORD)
 ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
+   ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
 
-_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
+#define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
   /**
    *  Base class, general case.  It is a class invariant that _Nw will be
@@ -73,108 +77,107 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       /// 0 is the least significant word.
       _WordT           _M_w[_Nw];
 
-      _Base_bitset()
-      { _M_do_reset(); }
+      _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
+      : _M_w() { }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      _Base_bitset(unsigned long long __val)
+      constexpr _Base_bitset(unsigned long long __val) noexcept
+      : _M_w{ _WordT(__val)
+#if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
+              , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
+#endif
+       } { }
 #else
       _Base_bitset(unsigned long __val)
+      : _M_w()
+      { _M_w[0] = __val; }
 #endif
-      {
-       _M_do_reset();
-       _M_w[0] = __val;
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-       if (sizeof(unsigned long long) > sizeof(unsigned long))
-         _M_w[1] = __val >> _GLIBCXX_BITSET_BITS_PER_WORD;
-#endif
-      }
 
-      static size_t
-      _S_whichword(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static size_t
-      _S_whichbyte(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
-      static size_t
-      _S_whichbit(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
       { return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static _WordT
-      _S_maskbit(size_t __pos )
+      static _GLIBCXX_CONSTEXPR _WordT
+      _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
       _WordT&
-      _M_getword(size_t __pos)
+      _M_getword(size_t __pos) _GLIBCXX_NOEXCEPT
       { return _M_w[_S_whichword(__pos)]; }
 
-      _WordT
-      _M_getword(size_t __pos) const
+      _GLIBCXX_CONSTEXPR _WordT
+      _M_getword(size_t __pos) const _GLIBCXX_NOEXCEPT
       { return _M_w[_S_whichword(__pos)]; }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      const char*
-      _M_getdata() const
-      { return reinterpret_cast<const char*>(_M_w); }
+      const _WordT*
+      _M_getdata() const noexcept
+      { return _M_w; }
 #endif
 
       _WordT&
-      _M_hiword()
+      _M_hiword() _GLIBCXX_NOEXCEPT
       { return _M_w[_Nw - 1]; }
 
-      _WordT
-      _M_hiword() const
+      _GLIBCXX_CONSTEXPR _WordT
+      _M_hiword() const _GLIBCXX_NOEXCEPT
       { return _M_w[_Nw - 1]; }
 
       void
-      _M_do_and(const _Base_bitset<_Nw>& __x)
+      _M_do_and(const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
       {
        for (size_t __i = 0; __i < _Nw; __i++)
          _M_w[__i] &= __x._M_w[__i];
       }
 
       void
-      _M_do_or(const _Base_bitset<_Nw>& __x)
+      _M_do_or(const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
       {
        for (size_t __i = 0; __i < _Nw; __i++)
          _M_w[__i] |= __x._M_w[__i];
       }
 
       void
-      _M_do_xor(const _Base_bitset<_Nw>& __x)
+      _M_do_xor(const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
       {
        for (size_t __i = 0; __i < _Nw; __i++)
          _M_w[__i] ^= __x._M_w[__i];
       }
 
       void
-      _M_do_left_shift(size_t __shift);
+      _M_do_left_shift(size_t __shift) _GLIBCXX_NOEXCEPT;
 
       void
-      _M_do_right_shift(size_t __shift);
+      _M_do_right_shift(size_t __shift) _GLIBCXX_NOEXCEPT;
 
       void
-      _M_do_flip()
+      _M_do_flip() _GLIBCXX_NOEXCEPT
       {
        for (size_t __i = 0; __i < _Nw; __i++)
          _M_w[__i] = ~_M_w[__i];
       }
 
       void
-      _M_do_set()
+      _M_do_set() _GLIBCXX_NOEXCEPT
       {
        for (size_t __i = 0; __i < _Nw; __i++)
          _M_w[__i] = ~static_cast<_WordT>(0);
       }
 
       void
-      _M_do_reset()
+      _M_do_reset() _GLIBCXX_NOEXCEPT
       { __builtin_memset(_M_w, 0, _Nw * sizeof(_WordT)); }
 
       bool
-      _M_is_equal(const _Base_bitset<_Nw>& __x) const
+      _M_is_equal(const _Base_bitset<_Nw>& __x) const _GLIBCXX_NOEXCEPT
       {
        for (size_t __i = 0; __i < _Nw; ++__i)
          if (_M_w[__i] != __x._M_w[__i])
@@ -182,18 +185,20 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        return true;
       }
 
-      size_t
-      _M_are_all_aux() const
-      {
-       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
+      _M_is_any() const _GLIBCXX_NOEXCEPT
       {
        for (size_t __i = 0; __i < _Nw; __i++)
          if (_M_w[__i] != static_cast<_WordT>(0))
@@ -202,7 +207,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       }
 
       size_t
-      _M_do_count() const
+      _M_do_count() const _GLIBCXX_NOEXCEPT
       {
        size_t __result = 0;
        for (size_t __i = 0; __i < _Nw; __i++)
@@ -220,17 +225,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
       // find first "on" bit
       size_t
-      _M_do_find_first(size_t __not_found) const;
+      _M_do_find_first(size_t) const _GLIBCXX_NOEXCEPT;
 
       // find the next "on" bit that follows "prev"
       size_t
-      _M_do_find_next(size_t __prev, size_t __not_found) const;
+      _M_do_find_next(size_t, size_t) const _GLIBCXX_NOEXCEPT;
     };
 
   // Definitions of non-inline functions from _Base_bitset.
   template<size_t _Nw>
     void
-    _Base_bitset<_Nw>::_M_do_left_shift(size_t __shift)
+    _Base_bitset<_Nw>::_M_do_left_shift(size_t __shift) _GLIBCXX_NOEXCEPT
     {
       if (__builtin_expect(__shift != 0, 1))
        {
@@ -256,7 +261,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
   template<size_t _Nw>
     void
-    _Base_bitset<_Nw>::_M_do_right_shift(size_t __shift)
+    _Base_bitset<_Nw>::_M_do_right_shift(size_t __shift) _GLIBCXX_NOEXCEPT
     {
       if (__builtin_expect(__shift != 0, 1))
        {
@@ -310,7 +315,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
   template<size_t _Nw>
     size_t
-    _Base_bitset<_Nw>::_M_do_find_first(size_t __not_found) const
+    _Base_bitset<_Nw>::
+    _M_do_find_first(size_t __not_found) const _GLIBCXX_NOEXCEPT
     {
       for (size_t __i = 0; __i < _Nw; __i++)
        {
@@ -325,7 +331,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
   template<size_t _Nw>
     size_t
-    _Base_bitset<_Nw>::_M_do_find_next(size_t __prev, size_t __not_found) const
+    _Base_bitset<_Nw>::
+    _M_do_find_next(size_t __prev, size_t __not_found) const _GLIBCXX_NOEXCEPT
     {
       // make bound inclusive
       ++__prev;
@@ -369,116 +376,118 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       typedef unsigned long _WordT;
       _WordT _M_w;
 
-      _Base_bitset(void)
+      _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
       : _M_w(0)
       { }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      _Base_bitset(unsigned long long __val)
+      constexpr _Base_bitset(unsigned long long __val) noexcept
 #else
       _Base_bitset(unsigned long __val)
 #endif
       : _M_w(__val)
       { }
 
-      static size_t
-      _S_whichword(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static size_t
-      _S_whichbyte(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
-      static size_t
-      _S_whichbit(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
       {  return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static _WordT
-      _S_maskbit(size_t __pos )
+      static _GLIBCXX_CONSTEXPR _WordT
+      _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
 
       _WordT&
-      _M_getword(size_t)
+      _M_getword(size_t) _GLIBCXX_NOEXCEPT
       { return _M_w; }
 
-      _WordT
-      _M_getword(size_t) const
+      _GLIBCXX_CONSTEXPR _WordT
+      _M_getword(size_t) const _GLIBCXX_NOEXCEPT
       { return _M_w; }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      const char*
-      _M_getdata() const
-      { return reinterpret_cast<const char*>(&_M_w); }
+      const _WordT*
+      _M_getdata() const noexcept
+      { return &_M_w; }
 #endif
 
       _WordT&
-      _M_hiword()
+      _M_hiword() _GLIBCXX_NOEXCEPT
       { return _M_w; }
 
-      _WordT
-      _M_hiword() const
+      _GLIBCXX_CONSTEXPR _WordT
+      _M_hiword() const _GLIBCXX_NOEXCEPT
       { return _M_w; }
 
       void
-      _M_do_and(const _Base_bitset<1>& __x)
+      _M_do_and(const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
       { _M_w &= __x._M_w; }
 
       void
-      _M_do_or(const _Base_bitset<1>& __x)
+      _M_do_or(const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
       { _M_w |= __x._M_w; }
 
       void
-      _M_do_xor(const _Base_bitset<1>& __x)
+      _M_do_xor(const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
       { _M_w ^= __x._M_w; }
 
       void
-      _M_do_left_shift(size_t __shift)
+      _M_do_left_shift(size_t __shift) _GLIBCXX_NOEXCEPT
       { _M_w <<= __shift; }
 
       void
-      _M_do_right_shift(size_t __shift)
+      _M_do_right_shift(size_t __shift) _GLIBCXX_NOEXCEPT
       { _M_w >>= __shift; }
 
       void
-      _M_do_flip()
+      _M_do_flip() _GLIBCXX_NOEXCEPT
       { _M_w = ~_M_w; }
 
       void
-      _M_do_set()
+      _M_do_set() _GLIBCXX_NOEXCEPT
       { _M_w = ~static_cast<_WordT>(0); }
 
       void
-      _M_do_reset()
+      _M_do_reset() _GLIBCXX_NOEXCEPT
       { _M_w = 0; }
 
       bool
-      _M_is_equal(const _Base_bitset<1>& __x) const
+      _M_is_equal(const _Base_bitset<1>& __x) const _GLIBCXX_NOEXCEPT
       { return _M_w == __x._M_w; }
 
-      size_t
-      _M_are_all_aux() const
-      { 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
+      _M_is_any() const _GLIBCXX_NOEXCEPT
       { return _M_w != 0; }
 
       size_t
-      _M_do_count() const
+      _M_do_count() const _GLIBCXX_NOEXCEPT
       { return __builtin_popcountl(_M_w); }
 
       unsigned long
-      _M_do_to_ulong() const
+      _M_do_to_ulong() const _GLIBCXX_NOEXCEPT
       { return _M_w; }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
       unsigned long long
-      _M_do_to_ullong() const
+      _M_do_to_ullong() const noexcept
       { return _M_w; }
 #endif
 
       size_t
-      _M_do_find_first(size_t __not_found) const
+      _M_do_find_first(size_t __not_found) const _GLIBCXX_NOEXCEPT
       {
         if (_M_w != 0)
           return __builtin_ctzl(_M_w);
@@ -489,6 +498,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       // find the next "on" bit that follows "prev"
       size_t
       _M_do_find_next(size_t __prev, size_t __not_found) const
+       _GLIBCXX_NOEXCEPT
       {
        ++__prev;
        if (__prev >= ((size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
@@ -512,30 +522,30 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
     {
       typedef unsigned long _WordT;
 
-      _Base_bitset()
+      _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
       { }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      _Base_bitset(unsigned long long)
+      constexpr _Base_bitset(unsigned long long) noexcept
 #else
       _Base_bitset(unsigned long)
 #endif
       { }
 
-      static size_t
-      _S_whichword(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
       { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static size_t
-      _S_whichbyte(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
       { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
 
-      static size_t
-      _S_whichbit(size_t __pos )
+      static _GLIBCXX_CONSTEXPR size_t
+      _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
       {  return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
 
-      static _WordT
-      _S_maskbit(size_t __pos )
+      static _GLIBCXX_CONSTEXPR _WordT
+      _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
@@ -546,85 +556,90 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       // make an unchecked call; all the memory ugliness is therefore
       // localized to this single should-never-get-this-far function.
       _WordT&
-      _M_getword(size_t) const
-      { 
+      _M_getword(size_t) _GLIBCXX_NOEXCEPT
+      {
        __throw_out_of_range(__N("_Base_bitset::_M_getword")); 
-       return *new _WordT; 
+       return *new _WordT;
       }
 
-      _WordT
-      _M_hiword() const
+      _GLIBCXX_CONSTEXPR _WordT
+      _M_getword(size_t __pos) const _GLIBCXX_NOEXCEPT
+      { return 0; }
+
+      _GLIBCXX_CONSTEXPR _WordT
+      _M_hiword() const _GLIBCXX_NOEXCEPT
       { return 0; }
 
       void
-      _M_do_and(const _Base_bitset<0>&)
+      _M_do_and(const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
       { }
 
       void
-      _M_do_or(const _Base_bitset<0>&)
+      _M_do_or(const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
       { }
 
       void
-      _M_do_xor(const _Base_bitset<0>&)
+      _M_do_xor(const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
       { }
 
       void
-      _M_do_left_shift(size_t)
+      _M_do_left_shift(size_t) _GLIBCXX_NOEXCEPT
       { }
 
       void
-      _M_do_right_shift(size_t)
+      _M_do_right_shift(size_t) _GLIBCXX_NOEXCEPT
       { }
 
       void
-      _M_do_flip()
+      _M_do_flip() _GLIBCXX_NOEXCEPT
       { }
 
       void
-      _M_do_set()
+      _M_do_set() _GLIBCXX_NOEXCEPT
       { }
 
       void
-      _M_do_reset()
+      _M_do_reset() _GLIBCXX_NOEXCEPT
       { }
 
       // Are all empty bitsets equal to each other?  Are they equal to
       // themselves?  How to compare a thing which has no state?  What is
       // the sound of one zero-length bitset clapping?
       bool
-      _M_is_equal(const _Base_bitset<0>&) const
+      _M_is_equal(const _Base_bitset<0>&) const _GLIBCXX_NOEXCEPT
       { return true; }
 
-      size_t
-      _M_are_all_aux() const
-      { return 0; }
+      template<size_t _Nb>
+        bool
+        _M_are_all() const _GLIBCXX_NOEXCEPT
+        { return true; }
 
       bool
-      _M_is_any() const
+      _M_is_any() const _GLIBCXX_NOEXCEPT
       { return false; }
 
       size_t
-      _M_do_count() const
+      _M_do_count() const _GLIBCXX_NOEXCEPT
       { return 0; }
 
       unsigned long
-      _M_do_to_ulong() const
+      _M_do_to_ulong() const _GLIBCXX_NOEXCEPT
       { return 0; }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
       unsigned long long
-      _M_do_to_ullong() const
+      _M_do_to_ullong() const noexcept
       { return 0; }
 #endif
 
       // Normally "not found" is the size, but that could also be
       // misinterpreted as an index in this corner case.  Oh well.
       size_t
-      _M_do_find_first(size_t) const
+      _M_do_find_first(size_t) const _GLIBCXX_NOEXCEPT
       { return 0; }
 
       size_t
-      _M_do_find_next(size_t, size_t) const
+      _M_do_find_next(size_t, size_t) const _GLIBCXX_NOEXCEPT
       { return 0; }
     };
 
@@ -633,16 +648,42 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
   template<size_t _Extrabits>
     struct _Sanitize
     {
-      static void _S_do_sanitize(unsigned long& __val)
-      { __val &= ~((~static_cast<unsigned long>(0)) << _Extrabits); }
+      typedef unsigned long _WordT;
+
+      static void
+      _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
+      { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
     };
 
   template<>
     struct _Sanitize<0>
-    { static void _S_do_sanitize(unsigned long) {} };
+    {
+      typedef unsigned long _WordT;
+
+      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
    *
@@ -714,11 +755,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       typedef unsigned long _WordT;
 
       void
-       _M_do_sanitize()
-       {
-         _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD>::
-           _S_do_sanitize(this->_M_hiword());
-       }
+      _M_do_sanitize() _GLIBCXX_NOEXCEPT
+      { 
+       typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
+       __sanitize_type::_S_do_sanitize(this->_M_hiword());
+      }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
       template<typename> friend class hash;
@@ -741,25 +782,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       {
        friend class bitset;
 
-       _WordT *_M_wp;
-       size_t _M_bpos;
+       _WordT_M_wp;
+       size_t  _M_bpos;
        
        // left undefined
        reference();
        
       public:
-       reference(bitset& __b, size_t __pos)
+       reference(bitset& __b, size_t __pos) _GLIBCXX_NOEXCEPT
        {
          _M_wp = &__b._M_getword(__pos);
          _M_bpos = _Base::_S_whichbit(__pos);
        }
 
-       ~reference()
+       ~reference() _GLIBCXX_NOEXCEPT
        { }
 
        // For b[i] = __x;
        reference&
-       operator=(bool __x)
+       operator=(bool __x) _GLIBCXX_NOEXCEPT
        {
          if (__x)
            *_M_wp |= _Base::_S_maskbit(_M_bpos);
@@ -770,7 +811,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
        // For b[i] = b[__j];
        reference&
-       operator=(const reference& __j)
+       operator=(const reference& __j) _GLIBCXX_NOEXCEPT
        {
          if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
            *_M_wp |= _Base::_S_maskbit(_M_bpos);
@@ -781,16 +822,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
        // Flips the bit
        bool
-       operator~() const
+       operator~() const _GLIBCXX_NOEXCEPT
        { return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
 
        // For __x = b[i];
-       operator bool() const
+       operator bool() const _GLIBCXX_NOEXCEPT
        { return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
 
        // For b[i].flip();
        reference&
-       flip()
+       flip() _GLIBCXX_NOEXCEPT
        {
          *_M_wp ^= _Base::_S_maskbit(_M_bpos);
          return *this;
@@ -800,24 +841,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
       // 23.3.5.1 constructors:
       /// All bits set to zero.
-      bitset()
+      _GLIBCXX_CONSTEXPR bitset() _GLIBCXX_NOEXCEPT
       { }
 
       /// Initial bits bitwise-copied from a single word (others set to zero).
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-      bitset(unsigned long long __val)
+      constexpr bitset(unsigned long long __val) noexcept
+      : _Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
 #else
       bitset(unsigned long __val)
-#endif
       : _Base(__val)
       { _M_do_sanitize(); }
+#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.
        */
@@ -836,11 +878,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        }
 
       /**
-       *  @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.
        */
@@ -871,48 +914,57 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
       /**
-       *  @brief  Construct from a string.
-       *  @param  str  A string of @a 0 and @a 1 characters.
-       *  @throw  std::invalid_argument  If a character appears in the string
-       *                                 which is neither @a 0 nor @a 1.
+       *  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.
        */
-      explicit
-      bitset(const char* __str)
-      : _Base()
-      {
-       if (!__str)
-         __throw_logic_error(__N("bitset::bitset(const char*)"));
-
-       const size_t __len = __builtin_strlen(__str);
-       _M_copy_from_ptr<char, std::char_traits<char>>(__str, __len, 0,
-                                                      __len, '0', '1');
-      }
+      template<typename _CharT>
+        explicit
+        bitset(const _CharT* __str,
+              typename std::basic_string<_CharT>::size_type __n
+              = std::basic_string<_CharT>::npos,
+              _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
+        : _Base()
+        {
+         if (!__str)
+           __throw_logic_error(__N("bitset::bitset(const _CharT*, ...)"));
+
+         if (__n == std::basic_string<_CharT>::npos)
+           __n = std::char_traits<_CharT>::length(__str);
+         _M_copy_from_ptr<_CharT, std::char_traits<_CharT>>(__str, __n, 0,
+                                                            __n, __zero,
+                                                            __one);
+       }
 #endif
 
       // 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.
        */
       bitset<_Nb>&
-      operator&=(const bitset<_Nb>& __rhs)
+      operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
       {
        this->_M_do_and(__rhs);
        return *this;
       }
 
       bitset<_Nb>&
-      operator|=(const bitset<_Nb>& __rhs)
+      operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
       {
        this->_M_do_or(__rhs);
        return *this;
       }
 
       bitset<_Nb>&
-      operator^=(const bitset<_Nb>& __rhs)
+      operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
       {
        this->_M_do_xor(__rhs);
        return *this;
@@ -921,13 +973,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       
       //@{
       /**
-       *  @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.
        */
       bitset<_Nb>&
-      operator<<=(size_t __position)
+      operator<<=(size_t __position) _GLIBCXX_NOEXCEPT
       {
        if (__builtin_expect(__position < _Nb, 1))
          {
@@ -940,7 +992,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       }
 
       bitset<_Nb>&
-      operator>>=(size_t __position)
+      operator>>=(size_t __position) _GLIBCXX_NOEXCEPT
       {
        if (__builtin_expect(__position < _Nb, 1))
          {
@@ -960,14 +1012,14 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        *  @ingroup SGIextensions
        */
       bitset<_Nb>&
-      _Unchecked_set(size_t __pos)
+      _Unchecked_set(size_t __pos) _GLIBCXX_NOEXCEPT
       {
        this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
        return *this;
       }
 
       bitset<_Nb>&
-      _Unchecked_set(size_t __pos, int __val)
+      _Unchecked_set(size_t __pos, int __val) _GLIBCXX_NOEXCEPT
       {
        if (__val)
          this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
@@ -977,21 +1029,21 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       }
 
       bitset<_Nb>&
-      _Unchecked_reset(size_t __pos)
+      _Unchecked_reset(size_t __pos) _GLIBCXX_NOEXCEPT
       {
        this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
        return *this;
       }
 
       bitset<_Nb>&
-      _Unchecked_flip(size_t __pos)
+      _Unchecked_flip(size_t __pos) _GLIBCXX_NOEXCEPT
       {
        this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
        return *this;
       }
 
-      bool
-      _Unchecked_test(size_t __pos) const
+      _GLIBCXX_CONSTEXPR bool
+      _Unchecked_test(size_t __pos) const _GLIBCXX_NOEXCEPT
       { return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
                != static_cast<_WordT>(0)); }
       //@}
@@ -1001,7 +1053,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        *  @brief Sets every bit to true.
        */
       bitset<_Nb>&
-      set()
+      set() _GLIBCXX_NOEXCEPT
       {
        this->_M_do_set();
        this->_M_do_sanitize();
@@ -1010,8 +1062,8 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
       /**
        *  @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>&
@@ -1026,7 +1078,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        *  @brief Sets every bit to false.
        */
       bitset<_Nb>&
-      reset()
+      reset() _GLIBCXX_NOEXCEPT
       {
        this->_M_do_reset();
        return *this;
@@ -1034,7 +1086,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
       /**
        *  @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).
@@ -1051,7 +1103,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        *  @brief Toggles every bit to its opposite value.
        */
       bitset<_Nb>&
-      flip()
+      flip() _GLIBCXX_NOEXCEPT
       {
        this->_M_do_flip();
        this->_M_do_sanitize();
@@ -1060,7 +1112,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
       /**
        *  @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>&
@@ -1073,15 +1125,15 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       
       /// See the no-argument flip().
       bitset<_Nb>
-      operator~() const
+      operator~() const _GLIBCXX_NOEXCEPT
       { return bitset<_Nb>(*this).flip(); }
 
       //@{
       /**
        *  @brief  Array-indexing support.
-       *  @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.
+       *  @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,
        *         as required by DR 11 to the standard.
        *
@@ -1093,9 +1145,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        */
       reference
       operator[](size_t __position)
-      { return reference(*this,__position); }
+      { return reference(*this, __position); }
 
-      bool
+      _GLIBCXX_CONSTEXPR bool
       operator[](size_t __position) const
       { return _Unchecked_test(__position); }
       //@}
@@ -1224,28 +1276,28 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
       /// Returns the number of bits which are set.
       size_t
-      count() const
+      count() const _GLIBCXX_NOEXCEPT
       { return this->_M_do_count(); }
 
       /// Returns the total number of bits.
-      size_t
-      size() const
+      _GLIBCXX_CONSTEXPR size_t
+      size() const _GLIBCXX_NOEXCEPT
       { return _Nb; }
 
       //@{
       /// These comparisons for equality/inequality are, well, @e bitwise.
       bool
-      operator==(const bitset<_Nb>& __rhs) const
+      operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
       { return this->_M_is_equal(__rhs); }
 
       bool
-      operator!=(const bitset<_Nb>& __rhs) const
+      operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
       { return !this->_M_is_equal(__rhs); }
       //@}
       
       /**
        *  @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.
        */
@@ -1264,15 +1316,15 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        *  @return  True if all the bits are set.
        */
       bool
-      all() const
-      { return this->_M_are_all_aux() == _Nb; }
+      all() const _GLIBCXX_NOEXCEPT
+      { return this->template _M_are_all<_Nb>(); }
 
       /**
        *  @brief Tests whether any of the bits are on.
        *  @return  True if at least one bit is set.
        */
       bool
-      any() const
+      any() const _GLIBCXX_NOEXCEPT
       { return this->_M_is_any(); }
 
       /**
@@ -1280,17 +1332,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        *  @return  True if none of the bits are set.
        */
       bool
-      none() const
+      none() const _GLIBCXX_NOEXCEPT
       { return !this->_M_is_any(); }
 
       //@{
       /// Self-explanatory.
       bitset<_Nb>
-      operator<<(size_t __position) const
+      operator<<(size_t __position) const _GLIBCXX_NOEXCEPT
       { return bitset<_Nb>(*this) <<= __position; }
 
       bitset<_Nb>
-      operator>>(size_t __position) const
+      operator>>(size_t __position) const _GLIBCXX_NOEXCEPT
       { return bitset<_Nb>(*this) >>= __position; }
       //@}
       
@@ -1301,18 +1353,18 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        *  @sa  _Find_next
        */
       size_t
-      _Find_first() const
+      _Find_first() const _GLIBCXX_NOEXCEPT
       { return this->_M_do_find_first(_Nb); }
 
       /**
        *  @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
+      _Find_next(size_t __prev) const _GLIBCXX_NOEXCEPT
       { return this->_M_do_find_next(__prev, _Nb); }
     };
 
@@ -1325,7 +1377,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
                       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];
@@ -1355,15 +1407,15 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
   //@{
   /**
    *  @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.
   */
   template<size_t _Nb>
     inline bitset<_Nb>
-    operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
+    operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
     {
       bitset<_Nb> __result(__x);
       __result &= __y;
@@ -1372,7 +1424,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
   template<size_t _Nb>
     inline bitset<_Nb>
-    operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
+    operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
     {
       bitset<_Nb> __result(__x);
       __result |= __y;
@@ -1381,7 +1433,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
   template <size_t _Nb>
     inline bitset<_Nb>
-    operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y)
+    operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
     {
       bitset<_Nb> __result(__x);
       __result ^= __y;
@@ -1481,41 +1533,46 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
     }
   //@}
 
-_GLIBCXX_END_NESTED_NAMESPACE
+_GLIBCXX_END_NAMESPACE_CONTAINER
+} // namespace std
 
 #undef _GLIBCXX_BITSET_WORDS
 #undef _GLIBCXX_BITSET_BITS_PER_WORD
+#undef _GLIBCXX_BITSET_BITS_PER_ULL
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 
 #include <bits/functional_hash.h>
 
-_GLIBCXX_BEGIN_NAMESPACE(std)
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // DR 1182.
   /// std::hash specialization for bitset.
   template<size_t _Nb>
-    struct hash<_GLIBCXX_STD_D::bitset<_Nb>>
-    : public std::unary_function<_GLIBCXX_STD_D::bitset<_Nb>, size_t>
+    struct hash<_GLIBCXX_STD_C::bitset<_Nb>>
+    : public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
     {
       size_t
-      operator()(const _GLIBCXX_STD_D::bitset<_Nb>& __b) const
+      operator()(const _GLIBCXX_STD_C::bitset<_Nb>& __b) const noexcept
       {
-       const size_t __size = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
-       return std::_Fnv_hash::hash(__b._M_getdata(), __size);
+       const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
+       return std::_Hash_impl::hash(__b._M_getdata(), __clength);
       }
     };
 
   template<>
-    struct hash<_GLIBCXX_STD_D::bitset<0>>
-    : public std::unary_function<_GLIBCXX_STD_D::bitset<0>, size_t>
+    struct hash<_GLIBCXX_STD_C::bitset<0>>
+    : public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
     {
       size_t
-      operator()(const _GLIBCXX_STD_D::bitset<0>&) const
+      operator()(const _GLIBCXX_STD_C::bitset<0>&) const noexcept
       { return 0; }
     };
 
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
 
 #endif // __GXX_EXPERIMENTAL_CXX0X__