469,097 Members | 1,304 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,097 developers. It's quick & easy.

std::deque.pop_front & pop_back

bb
Hi,

Is there any specific reason why std::deque's pop_front & pop_back
does not return the removed object?

It could return the removed object by value (possibly atomically?)

Cheers.

Apr 5 '07 #1
2 6138
On 5 Apr, 09:14, "bb" <muralibal...@gmail.comwrote:
Hi,

Is there any specific reason why std::deque's pop_front & pop_back
does not return the removed object?

It could return the removed object by value (possibly atomically?)
Exception safety. If pop did remove the object and for some reason an
exception was thrown while creating the copy you could end up loosing
an object. Can't remember the exact details right now but some
googling should help.

--
Erik Wikström

Apr 5 '07 #2
On Apr 5, 9:14 am, "bb" <muralibal...@gmail.comwrote:
Hi,

Is there any specific reason why std::deque's pop_front & pop_back
does not return the removed object?

It could return the removed object by value (possibly atomically?)

Cheers.
The SGI's docs contain the reasoning - it's from queue's documentation
but it also applies for deque:
"One might wonder why pop() returns void, instead of value_type. That
is, why must one use front() and pop() to examine and remove the
element at the front of the queue, instead of combining the two in a
single member function? In fact, there is a good reason for this
design. If pop() returned the front element, it would have to return
by value rather than by reference: return by reference would create a
dangling pointer. Return by value, however, is inefficient: it
involves at least one redundant copy constructor call. Since it is
impossible for pop() to return a value in such a way as to be both
efficient and correct, it is more sensible for it to return no value
at all and to require clients to use front() to inspect the value at
the front of the queue."

Apr 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dan Trowbridge | last post: by
8 posts views Thread by Gernot Frisch | last post: by
7 posts views Thread by DevNull | last post: by
29 posts views Thread by NvrBst | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.