1

I'm attempting to implement quicksort in-place, using boost's threading facility. Unfortunately I'm getting an error about "", when my function is not overloaded. Code follows:

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <boost/thread.hpp>

template<typename T>
void quicksortInPlace(std::vector<T> &array,
                      size_t left,
                      size_t right,
                      size_t pivot)
{
    size_t storeIndex = left;
    // ...
    if (left < storeIndex)
    {
        boost::thread lessThread(quicksortInPlace,
                                 array,
                                 left+0,
                                 storeIndex-1,
                                 storeIndex-1);
        lessThread.join();
    }
    if (right > storeIndex)
    {
        boost::thread moreThread(quicksortInPlace,
                                 array,
                                 storeIndex+1,
                                 right+0,
                                 storeIndex+1);
        moreThread.join();
    }

}


int main()
{
    std::vector<std::string> stuff;
    stuff.push_back("two");
    stuff.push_back("one");
    size_t left  = 0;
    size_t right = 1;
    size_t pivot = 0;
    quicksortInPlace(stuff,left,right,pivot);
    return 0;
}

I'm getting the following compilation errors (using stlfilt to clean up g++ output: gfilt -width:o main.cpp)

BD Software STL Message Decryptor v3.10 for gcc 2/3/4
main.cpp: In function ‘void quicksortInPlace(vector<string> &, size_t, size_t, size_t)’:
main.cpp:56:   instantiated from here
main.cpp:36: error: No match for ‘boost::thread::thread(<unresolved overloaded function type>, vector<string> &, size_t, size_t, size_t)’
main.cpp:41: error: No match for ‘boost::thread::thread(<unresolved overloaded function type>, vector<string> &, size_t, size_t, size_t)’

Here, I've used "left+0" instead of left so that the error is not of the form

main.cpp:41: error: No match for ‘boost::thread::thread(<unresolved overloaded function type>, vector<string> &, size_t, size_t &, size_t)’

How can I remove this ambiguity?

JRG
  • 2,065
  • 2
  • 14
  • 29
  • 1
    I just wanted to mention that you do *not* really use Boosts threading facility. [`thread::join`](http://stackoverflow.com/questions/6241738/what-exactly-is-join-in-boost-c) waits until the thread is finished. :) – Xeo Jun 05 '11 at 17:31
  • @Xeo: No wonder the threaded version was taking longer than the unthreaded one :D – JRG Jun 05 '11 at 17:51

1 Answers1

3

It needs to be quicksortInPlace<T>.

Puppy
  • 144,682
  • 38
  • 256
  • 465