This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] Use noexcept in container' move constructors, etc
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 01 Jun 2011 18:14:13 +0200
- Subject: Re: [v3] Use noexcept in container' move constructors, etc
- References: <4DE64A8B.3010309@oracle.com>
On 06/01/2011 04:19 PM, Paolo Carlini wrote:
tested x86_64-linux, committed to mainline. Note: special case
std::deque. I don't think we can really manage to have its
move-constructor noexcept withing the current ABI... I'll look into it
a bit more.
Maybe it's doable. The idea is creating an "emptier then empty" deque,
that is no map allocated, as moved-from in the move-constructor. Then
the latter can be marked noexcept. Afterward, the map can be lazily
created when needed, upon inserts, push_back, what else, as a first
step, with an helper doing something like:
if (!this->_M_impl._M_map)
_M_initialize_map(0);
and then proceed normally. In members like size and empty it's enough to
check this->_M_impl._M_map and return zero of it's null. Thus we have an
additional conditional (for which we should use __builtin_expect) in
member functions but in exchange the move constructor becomes noexcept
and extremely fast. The backward compatibility seems also ok to me,
because we are not going to do the lazy construction of the map in the
default constructor etc, only the C++0x move constructor can do the
trick, thus ABI problems would be possible only for code move
constructing a deque, thus built in C++0x mode, and linked to old code.
But for C++0x mode we don't promise ABI guarantees in terms of linking
together *.o objects, in general. At the moment I'm more concerned with
the performance issue with size, empty, which normally are *extremely*
simple and would get a conditional, even if with builtin_expect.
If somebody has comments...
Paolo.