Reputation: 13145
How do I use a visitor with the find_if function? I'm guessing I need to do some class of magical bind and therefore this will not work:
typedef boost::variant<FileNode,DirectoryNode> Node;
typedef std::vector<Node> Nodes;
const Nodes& nodes;
IsFileNodeVisitor isFileNodeVisitor;
find_if (nodes.begin(), nodes.end(), isFileNodeVisitor);
class IsFileNodeVisitor: public boost::static_visitor<bool>
{
public:
bool operator()(const FileNode&) const {
return true;
}
bool operator()(const DirectoryNode&) const {
return false;
}
};
The idea of the code above is to give me an iterator to the first FileNode instance in the vector of nodes.
Upvotes: 2
Views: 448
Reputation: 511
I think that using boost bind should work :
std::find_if (nodes.begin(), nodes.end(),
boost::bind(&boost::apply_visitor<IsFileNodeVisitor,Node>,
IsFileNodeVisitor(), _1 )
);
Upvotes: 2