Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 4. Iterators > Item 27: Use distance and advance to convert a container...

Item 27: Use distance and advance to convert a container’s const_iterators to iterators

Item 26 points out that some container member functions that take iterators as parameters insist on iterators; const_iterators won’t do. So what do you do if you have a const_iterator in hand and you want to, say, insert a new value into a container at the position indicated by the iterator? Somehow you’ve got to turn your const_iterator into an iterator, and you have to take an active role in doing it, because, as Item 26 explains, there is no implicit conversion from const_iterator to iterator.

I know what you’re thinking. You’re thinking, “When all else fails, get a bigger hammer.” In the world of C++, that can mean only one thing: casting. Shame on you for such thoughts. Where do you get these ideas?


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial