[RFC] 403. basic_string::swap should not throw exceptions (Ready)
Paolo Carlini
pcarlini@suse.de
Sun Jan 18 14:40:00 GMT 2004
Hi,
according to the resolution of this DR (now Ready)
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#403
a throw clause should be added: "Throws: Shall not throw exceptions."
However, is also clarified that:
Note: There remains long standing concern over whether or not it
is possible to reasonably meet the 23.1 [lib.container.requirements]
paragraph 10 swap requirements when allocators are unequal. The
specification of basic_string::swap exception requirements is in no
way intended to address, prejudice, or otherwise impact that concern.
So, which are the implication for our implementation which reads:
template<typename _CharT, typename _Traits, typename _Alloc>
void basic_string<_CharT, _Traits, _Alloc>::swap(basic_string& __s)
{
if (_M_rep()->_M_is_leaked())
_M_rep()->_M_set_sharable();
if (__s._M_rep()->_M_is_leaked())
__s._M_rep()->_M_set_sharable();
if (this->get_allocator() == __s.get_allocator())
{
_CharT* __tmp = _M_data();
_M_data(__s._M_data());
__s._M_data(__tmp);
}
// The code below can usually be optimized away.
else
{
basic_string __tmp1(_M_ibegin(), _M_iend(), __s.get_allocator());
basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
this->get_allocator());
*this = __tmp2;
__s = __tmp1;
}
}
???
Looks ok to me, in that when the allocators are equal cannot throw. Do you
concur?
Thanks,
Paolo.
More information about the Libstdc++
mailing list