I have another one question about functions reference.
For example, I have such definition:
typedef boost::function<bool (Entity &handle)> behaviorRef;
std::map< std::string, ptr_vector<behaviorRef> > eventAssociation;
The first question is: how to insert values into such map object?
I tried:
eventAssociation.insert(std::pair< std::string, ptr_vector<behaviorRef> >(eventType, ptr_vector<behaviorRef>(callback)));
But the error:
no matching function for call to ‘boost::ptr_vector<boost::function<bool(Entity&)> >::push_back(Entity::behaviorRef&)’
And I undersatnd it, but can’t make workable code.
The second question is how to call such functions?
For example, I have one object of behaviorRef, how to call it with boost::bind with passing my own values?
PART 1
There’s no need to use a
ptr_vector.boost::functionhas value semantics, so can be stored in a standard container. So the following should work:Note the two arguments to the
vectorconstructor.If you did need a
ptr_vector(because you were using a noncopyable type), you’d need something like the following, sinceptr_vectordoesn’t have a constructor that populates the vector:PART 2
There’s no need to use
boost::bindfor calling the function (although you can use it to make it in the first place). The syntax for calling it is the same as for a normal function: