Hi all,
My Problem goes like this:
If I want to save function in a std::map, I have the map value be either pointer to function or either std::function.
If I want to allow lamda functions to be saved in the map , and the lamda uses captures , in order for it work , the value must be std::function , and I must wrap the lamda with std::function.
for example , look at this snippet:
Code:
class SomeClass{
private:
static std::map<void* , std::function<void()>> functionMap;
public :
void setNewKeyValue (void* key ,std::function<void()>& function){
functionMap[key] = function;
}
void setNewKeyValue (void* key ,void(*function)()){
functionMap[key] = function;
}
};
int main (void){
SomeClass someObject;
int x;
double y =8.8 ; //dumm example, just to clarify the question
SomeObject.setNewKeyValue((void*)&x,std::function([&y]{y=-1;}));
return 0;
}
my question is , is there some way of setNewKeyValue to wrap the lamda expression from the inside so the outside developer won't be needing to wrap every lamda that uses capture with std::function?
or even something else , is there any "clean" solution to allow lamda functions with uses captures to be stored in a std::map?