Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Container front and back behavior

Here is the quote from "Effective STL":

When you get an object from a container (via. e.g., front or back), what you set is a copy of what was contained. Copy in, copy out. That's the STL way.

I have had a hard time understanding this part. As far as I know front returns the reference of the first element (at least for std::vector). Could you please explain above sentence?

like image 870
Vardan Hovhannisyan Avatar asked Jun 10 '26 08:06

Vardan Hovhannisyan


1 Answers

This was actually an error in an earlier edition of the book. From the errata:

! 6/29/01 jk     20  The first para of Item 3 is incorrect:  front      7/25/04
                     and back do NOT return copies of elements, they 
                     return references to elements.  I 
                     removed all mention of front and back.

So the explanation of the sentence is: woops, time to get a new edition!

like image 126
Barry Avatar answered Jun 11 '26 20:06

Barry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!