Library Samples

[ Keywords | Classes | Data | Functions ]

Quick Index

THE LIBRARY SECTION
DESCRIPTION
NAMING CONVENTIONS


Classes

Add
BinaryFunction
Greater
Less
Multiply
Outputer
Predicate

Back to the top of Samples

Data

Back to the top of Samples

Global Functions

template <class I1, class I2> void Copy(I1 start, I1 end, I2 dest) ;
template <class I, class T> I Find(I start, I end, T value) ;
template <class I, class T, class P> I Find(I start, I end, T value, P fn) ;
template <class I, class T> T Accumulate(I start, I end, T value) ;
template <class I, class T, class F> T Accumulate(I start, const I end, T init, F fn) ;
template <class I, class F> void ForEach(I start, I end, F fn) ;
template <class T> void Swap(T& X, T& Y) ;
template <class I> void Sort(I start, I end) ;
template <class I, class P> void Sort(I start, I end, P fn) ;

Back to the top of Samples

THE LIBRARY SECTION

For each library (collection of header files) you are allowed to define one LIBRARY section in one of the header files. Use this section to discuss the classes, datatypes, and algorithms in the entire library. This documentation will appear on the root page to the html files for the library.

You can only define one LIBRARY section and the library name must match the libary name used in the config file or on the command line.

Back to the top of Samples

DESCRIPTION

Simple algorithms, all of which can be found in the STL. The first letter of each function, struct/class name has been capatalized to prevent naming conflicts with the STL functions.

Back to the top of Samples

NAMING CONVENTIONS

In template classes the following abbreviations are used.

  • I - iterator type, or something that can behave like an iterator.
  • T - value type, this is what you get when you dereference the iterator.
  • F - function type, a function object a pointer to a function.
  • P - predicate type, a function object or a pointer to a function that takes two parameters of type T and returns a bool. See functional.h

    If a template function or class requires more that one iterator, value, or function type the digits are appended. i.e.

    template void Copy(I1 start, I1 end, I2 dest);

    Here 'start', and 'end' and of iterator type "I1" and 'dest' is of iterator type "I2". I1 and I2 may, or may not, be the same types of iterators.

  • Back to the top of Samples

    template <class I1, class I2> void Copy(I1 start, I1 end, I2 dest) ;

    #include "algorithm.h"

    Copies the objects pointed to by the iterators to dest. Objects in the range [start,end) are copied.

    Parameters

    in start
    Position to start copying from
    in end
    First element not to include in copying
    in dest
    Position to copy to

    template <class I1, class I2> void Copy(I1 start, I1 end, I2 dest)
                                                            
    ;

    Function is currently defined inline.


    Back to the top of Samples

    template <class I, class T> I Find(I start, I end, T value) ;

    #include "algorithm.h"

    This is a simple implementation of the STL find function

    Returns

  • end if the item is not found in the list
  • else an iterator of type I that can be used to reference the desired item.

    Parameters

    in start
    Position to start searching from
    in end
    First element not included in the search
    in value
    The value we are searching for

    template <class I, class T> I Find(I start, I end, T value)
                                                                                                                                      
    ;

    Function is currently defined inline.


    Back to the top of Samples

    template <class I, class T, class P> I Find(I start, I end, T value, P fn) ;

    #include "algorithm.h"

    A predicate version of the STL find

    The parameter class P is a predicate that is expected to take to parameters of type T and return a bool.

    Parameters

    in start
    Position to start searching from
    in end
    First element not included in the search
    in value
    The value we are searching for
    in fn
    The predicate fuction to be applied to determine if an element has been "found"

    template <class I, class T, class P> I Find(I start, I end, T value, P fn)
                                                                                                                                         
    ;

    Function is currently defined inline.


    Back to the top of Samples

    template <class I, class T> T Accumulate(I start, I end, T value) ;

    #include "algorithm.h"

    STL accumulate function. Calculates the sum of all the values in the sequence [start,end). Assumes that operator+ has been defined for the type T.

    Parameters

    in start
    First element in the sequence to include in the sum.
    in end
    The first element not included in the sum such that *(end-1) is included in the sum.
    in value
    Used to pass in the initial value (in case we don't want to start at 0)

    template <class I, class T> T Accumulate(I start, I end, T value)
                                                                                    
    ;

    Function is currently defined inline.


    Back to the top of Samples

    template <class I, class T, class F> T Accumulate(I start, const I end, T init, F fn) ;

    #include "algorithm.h"

    A more general version of the accumulate function. The function applies the predicate fn to the values in the range [start,end) and accumlates the result. That is it calculates:

            init = fn(init, *i)
        

    for all i in the range [start,end). For example,

            Multiply multiplyer;
    	int a[] = {1,2,3,4,5,6};
    	int product = 1;     // identity value for multiplication
    	Accumulate(a, a+7, product, multiplier);
    	assert(product == 720);
        

    Parameters

    in start
    First value to be included in the accumulation
    in end
    First value not included in the accumulation
    in init
    Initial value
    in fn
    Function to be applied while accumulating

    template <class I, class T, class F> T Accumulate(I start, const I end, T init, F fn)
                                                                                    
    ;

    Function is currently defined inline.


    Back to the top of Samples

    template <class I, class F> void ForEach(I start, I end, F fn) ;

    #include "algorithm.h"

    Applies the function fn(*i) to each i in the range

    start, end). The parameter fn should be a function
    object or a pointer to a function.

    Parameters
    in start
    First value fn() will be applied to
    in end
    First value fn() will not be applied to
    in fn
    The function to be applied

    template <class I, class F> void ForEach(I start, I end, F fn)
                                                      
    ;

    Function is currently defined inline.


    Back to the top of Samples

    template <class T> void Swap(T& X, T& Y) ;

    #include "algorithm.h"

    Takes two references are parameters and swaps their values.

    template <class T> void Swap(T& X, T& Y)
                                                
    ;

    Function is currently defined inline.


    Back to the top of Samples

    template <class I> void Sort(I start, I end) ;

    #include "algorithm.h"

    Bubble sorts the values in the range [start, end). Sorts with operator < .

    template <class I> void Sort(I start, I end)
                                                                                                                                                                                                                                                 
    ;

    Function is currently defined inline.


    Back to the top of Samples

    template <class I, class P> void Sort(I start, I end, P fn) ;

    #include "algorithm.h"

    Predicate version of BubbleSort. Uses the Predicate function fn to compare values. For example, given an STL vector of integers:

            extern vector ints;
    	Outputer
    	Sort(ints.begin(), ints.end(), Greater());
    	ForEach(ints.begin(), ints.end(), Outputer(' '));
    
    	Sort(int.begin(), ints.end(), Less());
    	ForEach(ints.begin(), ints.end(), Outputer
        

    template <class I, class P> void Sort(I start, I end, P fn)
                                                                                                                                                                                                                                                     
    ;

    Function is currently defined inline.


    Back to the top of Samples

    Generated from source by the Cocoon utilities on Wed Jan 31 13:59:35 2001 .

    Report problems to jkotula@vitalimages.com