Commit c5589aa7 by François Dumont Committed by François Dumont

bitset (bitset<>::reference): Clean code, use normal reference type in experimental mode.

2010-11-27  François Dumont  <francois.cppdevs@free.fr>

        * include/debug/bitset (bitset<>::reference): Clean code, use normal 
        reference type in experimental mode.
        * testsuite/23_containers/bitset/debug/invalid/1.cc: Fix for
        experimental mode.

From-SVN: r167196
parent a693d3a8
2010-11-27 François Dumont <francois.cppdevs@free.fr>
* include/debug/bitset (bitset<>::reference): Clean code, use normal
reference type in experimental mode.
* testsuite/23_containers/bitset/debug/invalid/1.cc: Fix for
experimental mode.
2010-11-26 François Dumont <francois.cppdevs@free.fr> 2010-11-26 François Dumont <francois.cppdevs@free.fr>
* testsuite/lib/libstdc++.exp ([check_v3_target_debug_mode]): Use * testsuite/lib/libstdc++.exp ([check_v3_target_debug_mode]): Use
......
...@@ -49,12 +49,16 @@ namespace __debug ...@@ -49,12 +49,16 @@ namespace __debug
typedef _GLIBCXX_STD_D::bitset<_Nb> _Base; typedef _GLIBCXX_STD_D::bitset<_Nb> _Base;
public: public:
// In C++0x we rely on normal reference type to preserve the property
// of bitset to be use as a literal.
// TODO: Find an other solution.
#ifdef __GXX_EXPERIMENTAL_CXX0X__
typedef typename _Base::reference reference;
#else
// bit reference: // bit reference:
class reference class reference
: private _Base::reference : private _Base::reference
#ifndef __GXX_EXPERIMENTAL_CXX0X__
, public __gnu_debug::_Safe_iterator_base , public __gnu_debug::_Safe_iterator_base
#endif
{ {
typedef typename _Base::reference _Base_ref; typedef typename _Base::reference _Base_ref;
...@@ -64,27 +68,21 @@ namespace __debug ...@@ -64,27 +68,21 @@ namespace __debug
reference(const _Base_ref& __base, reference(const _Base_ref& __base,
bitset* __seq __attribute__((__unused__))) bitset* __seq __attribute__((__unused__)))
: _Base_ref(__base) : _Base_ref(__base)
#ifndef __GXX_EXPERIMENTAL_CXX0X__
, _Safe_iterator_base(__seq, false) , _Safe_iterator_base(__seq, false)
#endif
{ } { }
public: public:
reference(const reference& __x) reference(const reference& __x)
: _Base_ref(__x) : _Base_ref(__x)
#ifndef __GXX_EXPERIMENTAL_CXX0X__
, _Safe_iterator_base(__x, false) , _Safe_iterator_base(__x, false)
#endif
{ } { }
reference& reference&
operator=(bool __x) operator=(bool __x)
{ {
#ifndef __GXX_EXPERIMENTAL_CXX0X__
_GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
_M_message(__gnu_debug::__msg_bad_bitset_write) _M_message(__gnu_debug::__msg_bad_bitset_write)
._M_iterator(*this)); ._M_iterator(*this));
#endif
*static_cast<_Base_ref*>(this) = __x; *static_cast<_Base_ref*>(this) = __x;
return *this; return *this;
} }
...@@ -92,14 +90,12 @@ namespace __debug ...@@ -92,14 +90,12 @@ namespace __debug
reference& reference&
operator=(const reference& __x) operator=(const reference& __x)
{ {
#ifndef __GXX_EXPERIMENTAL_CXX0X__
_GLIBCXX_DEBUG_VERIFY(! __x._M_singular(), _GLIBCXX_DEBUG_VERIFY(! __x._M_singular(),
_M_message(__gnu_debug::__msg_bad_bitset_read) _M_message(__gnu_debug::__msg_bad_bitset_read)
._M_iterator(__x)); ._M_iterator(__x));
_GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
_M_message(__gnu_debug::__msg_bad_bitset_write) _M_message(__gnu_debug::__msg_bad_bitset_write)
._M_iterator(*this)); ._M_iterator(*this));
#endif
*static_cast<_Base_ref*>(this) = __x; *static_cast<_Base_ref*>(this) = __x;
return *this; return *this;
} }
...@@ -107,36 +103,31 @@ namespace __debug ...@@ -107,36 +103,31 @@ namespace __debug
bool bool
operator~() const operator~() const
{ {
#ifndef __GXX_EXPERIMENTAL_CXX0X__
_GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
_M_message(__gnu_debug::__msg_bad_bitset_read) _M_message(__gnu_debug::__msg_bad_bitset_read)
._M_iterator(*this)); ._M_iterator(*this));
#endif
return ~(*static_cast<const _Base_ref*>(this)); return ~(*static_cast<const _Base_ref*>(this));
} }
operator bool() const operator bool() const
{ {
#ifndef __GXX_EXPERIMENTAL_CXX0X__
_GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
_M_message(__gnu_debug::__msg_bad_bitset_read) _M_message(__gnu_debug::__msg_bad_bitset_read)
._M_iterator(*this)); ._M_iterator(*this));
#endif
return *static_cast<const _Base_ref*>(this); return *static_cast<const _Base_ref*>(this);
} }
reference& reference&
flip() flip()
{ {
#ifndef __GXX_EXPERIMENTAL_CXX0X__
_GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(),
_M_message(__gnu_debug::__msg_bad_bitset_flip) _M_message(__gnu_debug::__msg_bad_bitset_flip)
._M_iterator(*this)); ._M_iterator(*this));
#endif
_Base_ref::flip(); _Base_ref::flip();
return *this; return *this;
} }
}; };
#endif
// 23.3.5.1 constructors: // 23.3.5.1 constructors:
_GLIBCXX_CONSTEXPR bitset() : _Base() { } _GLIBCXX_CONSTEXPR bitset() : _Base() { }
...@@ -269,7 +260,11 @@ namespace __debug ...@@ -269,7 +260,11 @@ namespace __debug
operator[](size_t __pos) operator[](size_t __pos)
{ {
__glibcxx_check_subscript(__pos); __glibcxx_check_subscript(__pos);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
return _M_base()[__pos];
#else
return reference(_M_base()[__pos], this); return reference(_M_base()[__pos], this);
#endif
} }
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
......
...@@ -34,7 +34,9 @@ void test01() ...@@ -34,7 +34,9 @@ void test01()
i = new bitset<32>::reference(bs[7]); i = new bitset<32>::reference(bs[7]);
VERIFY(*i); VERIFY(*i);
} }
#ifndef __GXX_EXPERIMENTAL_CXX0X__
VERIFY(i->_M_singular()); VERIFY(i->_M_singular());
#endif
delete i; delete i;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment