Check if element is in the list (contains)

后端 未结 7 1962
南笙
南笙 2021-01-31 14:38

I\'ve got a list of elements, say, integers and I want to check if my variable (another integer) is one of the elements from the list. In python I\'d do:

my_list         


        
7条回答
  •  情话喂你
    2021-01-31 15:24

    They really should add a wrapper. Like this:

    namespace std
    {
        template inline
            bool contains(_container _C, const _Ty& _Val)
            {return std::find(_C.begin(), _C.end(), _Val) != _C.end(); }
    };
    ...
        if( std::contains(my_container, what_to_find) )
        {
    
        }
    

提交回复
热议问题