Create a template which declares STL iterator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ken.carlino@gmail.com

    #1

    Create a template which declares STL iterator

    Hi,
    I have the following code which comples:

    bool contains(vector <A*>& cgl, A* cg) {

    vector<A*>::ite rator iter = find_if ( cgl.begin(), cgl.end(), bind(
    equal_to<A*>(), _1, cg ));

    return (iter != cgl.end());
    }

    anb how I want to create a template of the above code:
    template<class T1, class T2>
    bool contains(T1& cgl, T2 cg) {
    // this is line 189 of Utils.h
    T1::iterator iter = find_if ( cgl.begin(), cgl.end(),
    boost::lambda:: bind( equal_to<T2>(), boost::lambda:: _1, cg ));

    return (iter != cgl.end());
    }


    but I have the compile error:
    .../Utils.h: In function 'bool contains(T1&, T2)':
    .../Utils.h:189: error: expected `;' before 'iter'
    .../Utils.h:191: error: 'iter' was not declared in this scope

    Thanks for any idea.

  • Victor Bazarov

    #2
    Re: Create a template which declares STL iterator

    ken.carlino@gma il.com wrote:[color=blue]
    > [..]
    > // this is line 189 of Utils.h
    > T1::iterator iter = find_if ( cgl.begin(), cgl.end(),[/color]

    You probably want to make it

    typename T1::iterator iter = ...
    [color=blue]
    > boost::lambda:: bind( equal_to<T2>(), boost::lambda:: _1, cg ));
    >
    > return (iter != cgl.end());
    > }
    >
    >
    > but I have the compile error:
    > ../Utils.h: In function 'bool contains(T1&, T2)':
    > ../Utils.h:189: error: expected `;' before 'iter'
    > ../Utils.h:191: error: 'iter' was not declared in this scope
    >
    > Thanks for any idea.[/color]


    V
    --
    Please remove capital As from my address when replying by mail


    Comment

    Working...