Given this class:
class C
{
private:
struct Foo
{
int key1, key2, value;
};
std::vector<Foo> fooList;
};
The idea here is that fooList
can be indexed by either key1
or key2
of the Foo struct. I'm trying to write functors to pass to std::find_if
so I can look up items in fooList
by each key. But I can't get them to compile because Foo
is private within the class (it's not part of C's interface). Is there a way to do this without exposing Foo
to the rest of the world?
Here's an example of code that won't compile because Foo
is private within my class:
struct MatchKey1 : public std::unary_function<Foo, bool>
{
int key;
MatchKey1(int k) : key(k) {}
bool operator()(const Foo& elem) const
{
return key == elem.key1;
}
};