C++
  Home arrow C++ arrow Page 4 - The Standard Template Library
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

The Standard Template Library
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-06-24

    Table of Contents:
  • The Standard Template Library
  • History Class
  • Looking Inside the Library
  • Iterators

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Standard Template Library - Iterators


    (Page 4 of 4 )

    As you may have observed by now, each private/protected member is preceded by _ mark. The pop_back function shouldn’t be so hard to decrypt, so I leave that to you. Instead, take a look at the _Assign_n function. It’s a function for internal usage and you can see the begin() function in it. You should know that begin() returns an iterator to the first element in the array. But what exactly is an iterator?

    Well, iterators can be perceived as pointers; a smarter pointer, more like a generalization of pointers, that have extended capabilities aside from pointing to a concrete member. They can be used to iterate through a data structure. This can be achieved because C++ provides operator overriding for classes. This way we can step (iterate) further into the container by just using the ++operator, for example.

    The need for iterators occurs when you try to make some generic algorithms that do not depend on the container type. This way all generic algorithms (like the ones implemented in the algorithm’s header) can resolve most of the problems, regardless of the container type, by just getting two iterators that determine where to perform the algorithm.

    Of course, iterators can be more complex than that. There exist many types depending on the level of access that they give to the data structure. Input Iterator, Output Iterator, Forward Iterator, Bidirectional Iterator, and Random Access Iterator are all used in algorithms, while a sixth concept, Trivial Iterator, is introduced only to clarify the definitions of the other iterator concepts. Debating over each of them is beyond the purpose of this article, but feel free to read about them in the official SGI documentation.

    A very important note about iterators: always—and I mean always—use the ++iterator form instead of iterator++ if you can. It is more recommended purely for reasons related to performance. The second one creates a local variable in order to increase the iterator, and in an iteration, the time needed to create that local variable can add up significantly. But the first one just does what it’s asked: increase the iterator directly without creating a local variable.

    Conclusions

    Here we are at the end of part one. I really hope that you understood some basic ideas about how STL was created. This first part only introduced you to the way it looks at the internal level. Next time, I shall present the existing data structures and some basic ways to use them. By the time you reach the end of that segment, you should have a good bit of knowledge about STL.

    Until then, please try to pick up the main ideas included in this article. Don’t forget to ask any question about what was described here in the blog. Don’t hesitate to do so because procrastination leads nowhere.

    Also, if your goal is to ask for help from a community, then feel free to join one of our friendly forums. They are an online place where you’ll meet people that try to answer every little question you may have. Until we meet again, have some great moments and try to widen your knowledge on a consistent basis.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · STL is probably one of those things that can be attributed to the evolution of...
     

    C++ ARTICLES

    - More Tricks to Gain Speed in Programming Con...
    - Easy and Efficient Programming for Contests
    - Preparing For Programming Contests
    - Programming Contests: Why Bother?
    - Polymorphism in C++
    - Overview of Virtual Functions
    - Inheritance in C++
    - Extending the Basic Streams in C++
    - Using Stringstreams in C++
    - Custom Stream Manipulation in C++
    - General Stream Manipulation in C++
    - Serialize Your Class into Streams in C++
    - Advanced File Handling with Streams in C++
    - File Handling and Streams in C++
    - The STL String Class







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT