functors with reference parameters

R

red floyd

Disclaimer: VS.NET 2003 (haven't checked any other compiler).

I'm writing functors for my classes.
Because the objects in my containers are large, I'm making my functors take const T& parameters.

If I try std::bind2nd() with one of these classes, I get an error about a reference to a reference.

What's the proper way to declare functors taking const T& parameters so that they play nicely with adapters?

Would it be something like the following? What should I use as the params to unary_function? I can't quite
figure it out from Josuttis.

class myClass
{
// internals redacted
};

class myFunctor : public std::unary_function<myClass, void>
{
public:
void operator()(const myClass& elem)
{
// do something with elem here
}
};


TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top