Boost logo

Boost :

From: Darren Cook (darren_at_[hidden])
Date: 2004-05-13 04:31:56

I've a set of trees (e.g. a set of identically structured XML documents) and
I want to be able to return a reference to a certain position in the tree.
My test tree node is [1] below, with a test tree [2].

I think I can solve this with boost::function and boost::lambda. E.g. this

   boost::function1<int,Node&> best2;

I also need to be able to treat "number of children" the same way I can
treat value1 or value2. I've now worked this out as:


Going strong, but now I want to refer to the "value1 of the first child".
Following the patterns of the previous ones I thought it would be:

             bind( &std::vector<Node>::at, //Ask for an element
                  bind(&Node::children,_1), //Get the vector object
                  0 ) //Ask for element zero

That fails with a short error message [3], which is so rare when dealing
with BLL that I thought I might be able to understand it, but no, I couldn't
work out which bit it didn't like.

Can anyone help? Also, is there any limit to how deep I can nest these
binds? I think I'm going to need 3 more levels, but it would be useful to
know if it is unlimited.


class Node{
std::vector<Node> children;
int value1,value2;

Node(int v1,int v2):value1(v1),value2(v2){}

friend std::ostream& operator<<(std::ostream& s,const Node& obj){
return s;


[2] Example usage:
Node root(1,111);


function.cpp: In function `int main(int, char**)':
function.cpp:69: no matching function for call to `bind(<unknown type>, const
    boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
    boost::tuples::tuple<std::vector<Node, std::allocator<Node> > Node::*, const
    boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type,
    boost::tuples::null_type, boost::tuples::null_type> > >, int)'

Boost list run by bdawes at, gregod at, cpdaniel at, john at