CIS-255 Home http://www.c-jump.com/bcc/c255c/c255syllabus.htm

C++ Standard Library Part II


  1. STL containers
  2. std::stack
  3. std::set
  4. std::pair structure
  5. std::pair data members
  6. std::pair construction
  7. Functions returning a pair
  8. std::map
  9. std::map construction
  10. Adding items to a map
  11. Looking at a map
  12. map iterators
  13. map::find
  14. map::insert
  15. map::erase
  16. Map summary
  17. std::multimap
  18. std::multimap::equal_range
  19. STL Algorithms
  20. Iterators revisited
  21. Iterator types and functionality
  22. std::sort
  23. std::sort example
  24. Predicates
  25. std::count_if and predicate function
  26. std::count_if and predicate object

1. STL containers



2. std::stack



3. std::set



4. std::pair structure

  • 
    std::pair< T1, T2 >
    
    

    is a C++ structure that holds one object of type T1 and another one of type T2:

    
        #include <cassert>
        #include <string>
        #include <utility>
        using namespace std;
        int main (int argc, char* argv[])
        {
            pair< string, string > strstr;
            strstr.first = "Hello";
            strstr.second = "World";
    
            pair< int, string > intstr;
            intstr.first = 1;
            intstr.second = "one";
    
            pair< string, int > strint( "two", 2 );
            assert( strint.first == "two" );
            assert( strint.second == 2 );
    
            return 0;
        }
    
    
  • A pair is much like a container that holds exactly two elements.

  • The pair is defined in the standard header named utility.

5. std::pair data members



6. std::pair construction



7. Functions returning a pair



8. std::map



9. std::map construction



10. Adding items to a map



11. Looking at a map



12. map iterators



13. map::find



14. map::insert



15. map::erase



16. Map summary



17. std::multimap



18. std::multimap::equal_range



19. STL Algorithms



20. Iterators revisited



21. Iterator types and functionality


Access Type Iterator Type
Output Input Forward Bidirectional Random
Write *p=x   *p=x *p=x *p=x
Read   x=*p x=*p x=*p x=*p
Pointer   p->f p->f p->f p->f
Iteration ++p ++p ++p ++p
--p
++p p+n p-n p+=n p-=n
--p
Comparison   p==q
p!=q
p==q
p!=q
p==q
p!=q
p==q p>q p<q p>=q p<=q
p!=q
  • where

    • x is an item pointed by the iterator,

    • q is another iterator,

    • f is a data field in a struct,

    • n is an integer number.


22. std::sort



23. std::sort example



24. Predicates



25. std::count_if and predicate function



26. std::count_if and predicate object