syntax help required on templated static member function

Posted by omatai on Stack Overflow See other posts from Stack Overflow or by omatai
Published on 2010-03-23T02:22:06Z Indexed on 2010/03/23 2:51 UTC
Read the original article Hit count: 356

Filed under:
|
|

I have a bunch of containers of object pointers that I want to iterate through in different contexts to produce diagnostics for them. I'm struggling with the syntax required to define the functions... which, on account of these objects filtering through diverse parts of my application, seem best encapsulated in a dedicated diagnostics class thus:

// Code sketch only - detail fleshed out below...  
class ObjectListDiagnoser  
{  
public:  
    static void GenerateDiagnostics( /* help required here! */ );  
};  

...

// Elsewhere in the system...  
ObjectListDiagnoser::GenerateDiagnostics( /* help required here! */ );  

What I'd like to be able to do (in places across my application) is at least this:

std::vector<MyObject *> objGroup1;  
std::list<MyObject *> objGroup2;

ObjectListDiagnoser::GenerateDiagnostics( objGroup1.begin(), objGroup1.end() );  
ObjectListDiagnoser::GenerateDiagnostics( objGroup2.begin(), objGroup2.end() );  
ObjectListDiagnoser::GenerateDiagnostics( objGroup1.rbegin(), objGroup1.rend() );  

I have tried to template my function in two ways, with no success:

class ObjectListDiagnoser  
{  
public:  
    // 1 - nope.  
    template <class ObjIter>
    static void GenerateDiagnostics( ObjIter first, ObjIter last );  
    // 2. - nope.  
    template <class Container, class ObjIter>
    static void GenerateDiagnostics( Container<MyObject *>::ObjIter first,  
                                     Container<MyObject *>::ObjIter last );  
};  

Can someone provide the correct syntax for this? The container type will vary, and the direction of iteration will vary, but always for the same type of object.

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates