SmallChess
SmallChess

Reputation: 8126

Unable to compile a functor template

I'm trying to define a function

template<typename Functor> static void start(DataSize size, ThreadNum threadNum, Functor f)
{
    ....

    std::for_each<int>(allocated, size, f);

    ....
}

allocated and size are just int.

The caller calls the function

start(image.width() * image.height(), _threads, RGBHistogramFun<T>(image, hist));

and

template<typename T> class RGBHistogramFun
{
    ...

    void operator()(std::size_t i)
    {
        ....
    }
}

I set T to int for the template. I'm trying to define std::for_each so that it calls RGBHistogramFun::operator(std::size_t i) for each integer from allocated to size. The operator() will use the index to manipulate its internal array data.

However, I'm getting compiler error something about xutility.

Upvotes: 0

Views: 68

Answers (1)

ForEveR
ForEveR

Reputation: 55897

n3337 25.2.4

template<class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function f);

Effects: Applies f to the result of dereferencing every iterator in the range [first,last), starting from first and proceeding to last - 1.

int cannot be dereferenced.

Upvotes: 4

Related Questions