Thread: List of Functors

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138

    List of Functors

    I'm looking to optimize a portion of my code that is extremely time sensitive (will be running at least 1000x/s). It involves sequentially calling a series of functions to modify a given value. To avoid the overhead of function pointers, I would like to use functors allowing the compiler to inline. What I'm trying to do looks like the following:

    Code:
    typedef std::unary_function<DataType&, void> Func;
    
    ClassA InstanceOfA;
    ClassB InstanceOfB;
    
    class FuncA : public  Func{
         public:
              void operator()(DataType& d){
                   InstanceOfA.MemberFunc(d);
              }
    };
    
    class FuncB : public  Func{
         public:
              void operator()(DataType& d){
                   InstanceOfB.MemberFunc(d);
              }
    };
    
    ...
    
    std::list<Func> listOfFuncs;
    
    ...
    
    DataType val;
    std::list<Func>::iterator it = listOfFuncs.begin();
    (*it)(val)
    I can't seem to get it to work though. I must admit I've never used the unary_function STL base type. Am I using it improperly?
    Last edited by golfinguy4; 09-29-2009 at 11:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM