1

Can i do something like below ? Is it possible or is there any workaround?

..
PostWorkToThread( boost::bind(func_x, arg1) );
PostWorkToThread( boost::bind(func_y, arg1, arg2) );
PostWorkToThread( boost::bind(func_z, arg1, arg2, arg3) );
..


void PostWorkToThread( boost::bind xxx )
{
    PostWork( boost::bind(xxx) ); or
    PostWork( xxx );
}

Thank you, I appreciate your suggestion.

Maha
  • 11
  • 5

1 Answers1

0

Since the type of the function object generated by boost::bind (and std::bind) is not specified, you should make PostWorkToThread a template:

template< typename Fun >
void PostWorkToThread( Fun xxx )
{
    // Enqueue xxx for execution
}

Alternatively, you could use boost::function (or std::function) to erase the type of the function object:

void PostWorkToThread( boost::function< void() > const& xxx )
{
    // Enqueue xxx for execution
}

Note that in this case boost::function (and std::function) may have to dynamically allocate memory to store the function object. However, you will likely have to do it anyway to enqueue the function for execution, so this is probably not a problem.

Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27