473,327 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 6416
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dan Trowbridge | last post by:
He everyone, I just getting started with .NET and I am having a porting problem. I get and error in code that lookes like this (really stripped down but you get the idea)... class dt {...
1
by: bartek | last post by:
Hi, I'm sorry for asking such a simple question. I just would like to know what's the standard-defined behaviour when doing a push_back() on a std::deque. TIA, b
7
by: Dan Trowbridge | last post by:
He everyone, I am just getting started with .NET and I am having a porting problem. I get and error in code that lookssomething like this (really stripped down but you get the idea)... class...
8
by: Gernot Frisch | last post by:
std::deque<intd; d.push_front(13); int* p13 = &d.begin(); d.push_front(1); d.push_back(2); Can I be safe, that p13 points to 13? I mean, unless I erase the 13, of course.
7
by: DevNull | last post by:
Hello everyone, I decided to pick c++ back up after not really having used it much in 10 years. Just as a point of refference, there was no standard C++ last time I used regularly. Anyways...
29
by: NvrBst | last post by:
I've read a bit online seeing that two writes are not safe, which I understand, but would 1 thread push()'ing and 1 thread pop()'ing be thread-safe? Basically my situation is the follows: ...
3
by: Peng Yu | last post by:
Hi, I don't understand why rbegin() -rend() gives a negative number. Since rbegin() + 1 gives the one before the last element, I think rbegin() - rend() should give a positive number. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.