Boost :: thread and template functions

I try to run the template function in a separate thread, but IntelliSense (VC ++ 2010 Express) continues to give me an error: "Error: no instance of the constructor" boost :: thread :: thread "matches the argument list" and if I try to compile, I will get this error: "error C2661: 'boost :: thread :: thread': no ​​overloaded function takes 5 arguments

The error occurred only since I added the templates, so I am sure that this is something related to them, but I do not know what.

Two of the arguments I pass for boost :: thread are template functions defined as:

template<class F> 
void perform_test(int* current, int num_tests, F func, std::vector<std::pair<int, int>>* results);

and

namespace Sort
{

template<class RandomAccessIterator>
void quick(RandomAccessIterator begin, RandomAccessIterator end);

} //namespace Sort

I am trying to call boost :: thread like this:

std::vector<std::pair<int, int>> quick_results;
int current = 0, num_tests = 30;
boost::thread test_thread(perform_test, &current, num_tests, Sort::quick, &quick_results);
+3
2

- perform_test, 3 , . .

typedef std::vector<std::pair<int, int>> container;

template<class F> 
void perform_test(int* current, int num_tests, 
    void(* func)(typename F, typename F), container* results) 
{
    cout << "invoked thread function" << endl;
}

namespace Sort
{
    template<class RandomAccessIterator>
    void quick(RandomAccessIterator begin, RandomAccessIterator end)
    {
        cout << "invoked sort function" << endl;
    }

} //namespace Sort

int main()
{
    container quick_results;
    int current = 0, num_tests = 30;

    boost::thread test_thread(
        &perform_test<container::iterator>, 
        &current, 
        num_tests, 
        Sort::quick<container::iterator>, 
        &quick_results);    

    test_thread.join();
    return 0;
};
+2

"" . . , , . .

, :

typedef std::vector<std::pair<int, int>> container;
typedef container::iterator iterator;

boost::thread test_thread(
    &perform_test<Sort::quick<iterator>>, 
    &current, 
    num_tests, 
    &Sort::quick<iterator>, 
    &quick_results); 

.

+5

Source: https://habr.com/ru/post/1772387/


All Articles