函数对象无法识别它获得的param(std :: set <int>)

时间:2017-02-01 19:32:56

标签: c++ c++11 templates stl

我正在尝试编写一个使用函数对象的模板函数。 函数对象获取的参数是std::set(类型int)。 出于某种原因,当我试图用for(auto curr: set)抛出集合时,它甚至没有进入for循环,就像它不能识别它是一个stl集!

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;
}

这是模板:

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;
}

这是函数对象:

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;
        };
};

1 个答案:

答案 0 :(得分:1)

你永远不会把任何东西放到MoveDataTableCursor中,所以当然循环没有做任何事情。