Can someone explain me why some of these implementation works while other doesn't and what's happening under the hood? Is there some performance issue for example with f1?
What should I google for finding these mapping rules?
#include<string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <functional>
bool f1(const std::string& str1) //works
{
std::cout<<"f1"<<str1<<std::endl;
return true;
}
bool f2(std::string& str1) //not working
{
std::cout<<"f2"<<str1<<std::endl;
return true;
}
bool f3(std::string str1) //works
{
std::cout<<"f3"<<str1<<std::endl;
return true;
}
bool f4(std::string* str1)
{
std::cout<<"f4"<<str1<<std::endl;
return true;
}
int main(){
std::function<bool(std::string)> fp=&f1;
std::string x="Hello world";
fp(x);
return 0;
}