im trying to write a template function that use a function object. the param that the function object get is std::set (type int). for some reason, when im trying to go throw the set with: for(auto curr: set), it doesn't even go into the for loop, like it doesn't recognize it's a stl set!
please help!
MAIN:
int main()
{
Functor object_x;
SetInt set_1={1,2,6,4,3};
SetInt set_output;
set_output=mtmAlgorithem_2(set_output ,set_1,object_x);
return 0;
}
this is the template:
template < typename SetToReturn,typename Generic, typename Functor >
SetToReturn mtmAlgorithem_2(SetToReturn a,Generic input, Functor object){
//All elements after element X including X.
SetToReturn after_x;
//All elements before element X not-including X.
SetToReturn before_x;
//Output set
SetToReturn output;
//copy elements from input to after_x:
for(auto element: input){
after_x.insert(element);
}
for(auto element: input){
// > ---------THIS IS WERE I CALL THE FUNCTION OBJECT------
if(object(before_x,after_x)){
output.insert(element);
}
before_x.erase(element);
after_x.insert(element);
}
return output;
}
this is the function object:
class Functor
{
public:
bool operator()( SetInt &before_x, SetInt &after_x){
bool res=true;
for(int curr_1: before_x){
//------------not getting here---------------!!!!!!!!!!!!!!
for(int curr_2: after_x){
if(curr_1>curr_2){
res=false;
break;
}
}
}
std::cout<<"lla"<<std::endl;
return res;
};
};
Aucun commentaire:
Enregistrer un commentaire