Boost logo

Boost Users :

From: Hans Mull (hans72mull_at_[hidden])
Date: 2008-02-27 12:38:10


Hi! I want to use a boost::function pointer to a template function. The
template type should be determinated at the time the boost::function
object is initialized. Example:

template<class T>
inline string addNumber(T inputNumber)
{
    return lexical_cast<string>(inputNumber + 2);
}

template<class numType>
inline boost::function<string(numType)> getFunction(numType number)
{
    boost::function<string(numType)> f;
    f = //Which code can I use here? If I call f() I want to call
addNumber<numType>(number)
}

----------------------
I want to use it like that:

void callFunction()
{
boost::function<string(double)> f;
f = getFunction<unsigned long>();
for(int i = 0; i < 10000;i++)
{
 std::cout << f(rand()) << endl;
}
}

Thanks in advance, Hans


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net