I'm trying to have a function pointer where, in some cases, it either is assigned a function takes in 2 arguments (a cv::Mat and a struct that contains parameters) or a different function that takes 3 arguments (the same 2 arguments and a list of coordinates). I figure that std::function and std::bind are what I'm supposed to be using here.
Mat process_F1(cv::Mat img, feature_params f);
Mat process_F1_coords(cv::Mat img, feature_params f, std::vector<std::pair<int, int> > feature_coords c);
Mat process_F2(cv::Mat img, feature_params f);
Mat process_F2_coords(cv::Mat img, feature_params f, std::vector<std::pair<int, int> > feature_coords );
// this is the function pointer that will hold them
std::function<cv::Mat()> feature_func_f;
//this is how I assign them:
void set_feature_func(int feature_method, bool use_coords)
{
switch (feature_method){
case 0:
if( !use_coords )
feature_func_f = std::bind(process_F1,std::placeholders::_2);
else
feature_func_f = std::bind(process_F1_coords,std::placeholders::_3);
break;
case 1:
if( !use_coords )
feature_func_f = std::bind(process_F2,std::placeholders::_2);
else
feature_func_f = std::bind(process_F2_coords,std::placeholders::_3);
break;
}
I intend to call feature_func_f as:
cv::Mat m, n;
feature_params p;
set_feature_func(0,false);
n = feature_func_f(m,p);
// or if I have a coordinate list c
std::vector<std::pair<int, int> > c;
set_feature_func(0,true);
n = feature_func_f(m,p,c);
What am I doing wrong here? I get a bunch of errors that aren't really meaningful in the header for functional:
Error 4 error C2977: 'std::add_reference' : too many template arguments C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional 900 1
Error 5 error C2955: 'std::add_reference' : use of class template requires template argument list C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional 900 1
Error 6 error C2198: 'cv::Mat (__cdecl *)(cv::Mat,feature_params)' : too few arguments for call C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional 1149 1
Error 2 error C2146: syntax error : missing ',' before identifier 'type' C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional 900 1
Error 3 error C2065: 'type' : undeclared identifier C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional 900 1
Error 1 error C2027: use of undefined type 'std::tuple_element<0x01,_Ftuple>' C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional 900 1