I want to create a template for a std::function<T(Variable nums of arguments)> that returns the default value of a class by calling the default constructor.
I tried this:
template <class T,class... Args> inline std::function<T(Args...)> zero(){
return [](Args...){ return T();};
}
I want to use it in occasions where you just need the default value and no complicated function, for instance in my Image<T> class:
template <typename T> class Image{
...
void drawEachPixel(std::function<T(size_t,size_t)> func){
forRange(x,w){
forRange(y,h){
this->setPixel(x,y,func(x,y));
}
}
}
...
};
to clear an image I could just call:
image.drawEachPixel(zero());
when compiling I get the error no matching function for call to 'Image<unsigned char>::drawEachPixel(std::function<unsigned char()>)'...
Aucun commentaire:
Enregistrer un commentaire