Hello,
I'm trying to use the find algo from the stl library, over a list of
pointers:
std::list<Program *> m_programs
in this method:
Program *GLSLManager::GetProgram(GLhandleARB id)
{
std::list<Program *>::iterator result;
result = find(m_programs.begin(), m_programs.end(), id);
if(result!=m_programs.end())
return *result;
else
return NULL;
}
As far I know I must implement the operator== between the types
GLhandleARB (it is a typedef of ints) and Program * pointers. I do this
by this way:
int operator==(Program *program, GLhandleARB id); /*it is not a member
of Program class*/
[implementation]
int operator==(Program *program, GLhandleARB id)
{
return program->GetHandle() == id;
}
but I'm having errors with this:
error C2803: 'operator == must have at least a formal parameter of class
type'
Anyone can help me?
thanks in advance

Signature
Jacobo Rodríguez Villar
TyphoonLabs Lead Programmer
http://www.typhoonlabs.com
Vladimir Nesterovsky - 20 Dec 2004 14:49 GMT
> I'm trying to use the find algo from the stl library, over a list of
> pointers:
[quoted text clipped - 32 lines]
>
> thanks in advance
Your GLhandleARB is probably typedef of some primitive type or pointer. If
you could declare GLhandleARB as a struct, class, or enum you would
succeeded in operator== overloading.

Signature
Vladimir Nesterovsky
e-mail: vladimir@nesterovsky-bros.com
home: www.nesterovsky-bros.com
Tom Widmer - 20 Dec 2004 17:18 GMT
> Hello,
>
[quoted text clipped - 32 lines]
>
> Anyone can help me?
You can't overload operators for primitive types (I assume GLhandleARG
is just a typedef for a primitive type). Instead, you should use a
functor and find_if. e.g.
struct ProgramHandleChecker
{
GLhandleARB id;
ProgramHandleChecker(GLhandleARB id):id(id){}
bool operator()(Program* p) const
{
return p != 0 && id == p->GetHandle();
}
};
//...
result = find_if(m_programs.begin(), m_programs.end(),
ProgramHandleChecker(id));
If you use boost::bind (soon to be semi-standard as std::tr1::bind), you
can do:
result = find_if(m_programs.begin(), m_programs.end(),
bind<bool>(std::equals<GLhandleARB>(), bind(&Program::GetHandle, _1), id));
which saves the extra functor, but is more complex.
Tom
Jacobo Rodriguez Villar - 20 Dec 2004 21:19 GMT
Yes, GLhandleARB is a typedef of int, I'll try use it into a struct,
many thanks.
>> Hello,
>>
[quoted text clipped - 60 lines]
>
> Tom

Signature
Jacobo Rodríguez Villar
TyphoonLabs Lead Programmer
http://www.typhoonlabs.com