Hi,

Please advise how to bind std::sort with boost::thread.

I'm trying to do:

boost::thread_group thg;
thg.create_thread(boost::bind(sort<vector<int>::iterator>, mass.begin(), mass.end()));

and get: ThreadSort/main.cpp:40:0 /Users/Maxim/Documents/Projects/SW/C++/ThreadSort/main.cpp:40: error: no matching function for call to 'bind(<unresolved overloaded function type>, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >)'

Please HELP!!!

std::sort is an overloaded function, and this can cause problems with some compilers.
see: http://www.boost.org/doc/libs/1_37_0/libs/bind/bind.html#err_overloaded

The work-arounds are simple; this is one way:

typedef std::vector<int>::iterator iterator ;
void (*sort_function)( iterator, iterator ) = &std::sort ;
thg.create_thread( boost::bind( sort_function,
                                mass.begin(), mass.end() ) ;

I have found the solution!!!

boost::thread_group thg;
thg.create_thread(boost::bind(static_cast<void(*)(vector<int>::iterator,vector<int>::iterator)>(sort<vector<int>::iterator>), mass.begin(), mass.end()));

In any case thanks all of you!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.