Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 用于比较复合类型映射元素的find_if的lambda函数谓词_C++_If Statement_Find_Predicate - Fatal编程技术网

C++ 用于比较复合类型映射元素的find_if的lambda函数谓词

C++ 用于比较复合类型映射元素的find_if的lambda函数谓词,c++,if-statement,find,predicate,C++,If Statement,Find,Predicate,请参见下面的代码段: typedef boost::tuple<std::string, int, std::string> TUPLE; std::map<int, TUPLE> m; std::find_if ( m.begin(), m.end(), boost::lambda::bind ( &std::map<int, TUPLE>

请参见下面的代码段:

typedef boost::tuple<std::string, int, std::string> TUPLE;
std::map<int, TUPLE> m;

std::find_if
    (
        m.begin(),
        m.end(),
        boost::lambda::bind
            (
                &std::map<int, TUPLE>::value_type::second_type::head,
                boost::lambda::bind
                (
                    &std::map<int, TUPLE>::value_type::second,
                    boost::lambda::_1
                )
            )
        ==
        "someString"
    );
typedef boost::tuple tuple;
std::map m;
std::查找\u if
(
m、 begin(),
m、 end(),
boost::lambda::bind
(
&标准::映射::值类型::第二种类型::头,
boost::lambda::bind
(
&std::map::value\u type::second,
boost::lambda::_1
)
)
==
“一些字符串”
);
我试图为find_if(使用boost lambda)创建一个谓词,并将元组的第一个元素与字符串进行比较。然而,有没有办法使这项工作像这样:

typedef boost::tuple<std::string, int, std::string> TUPLE;
std::map<int, TUPLE> m;

std::find_if
    (
        m.begin(),
        m.end(),
        boost::lambda::bind
            (
                &std::map<int, TUPLE>::value_type::second_type::get<0>,
                boost::lambda::bind
                (
                    &std::map<int, TUPLE>::value_type::second,
                    boost::lambda::_1
                )
            )
        ==
        "someString"
    );
typedef boost::tuple tuple;
std::map m;
std::查找\u if
(
m、 begin(),
m、 end(),
boost::lambda::bind
(
&标准::映射::值类型::第二种类型::获取,
boost::lambda::bind
(
&std::map::value\u type::second,
boost::lambda::_1
)
)
==
“一些字符串”
);
我将second_type::head更改为second_type::get,但它不编译。 我试图创建一个谓词,将元组的第一个或第二个元素与某个字符串进行比较

这是我遇到的错误之一:

错误29错误C2780:'const boost::lambda::lambda_functor>,detail::bind_tuple_mapper::type>>boost::lambda::bind(const Arg1&'):需要1个参数-提供2个参数

有没有办法专门比较元组的第n个元素?(不仅仅是头部) 我尝试将tuple元素表示为struct,它可以工作,但如果有办法使用tuple,我将不胜感激


旁注:由于编译器版本的原因,我无法使用
[](){}
表示法。

好的,我不知道boost,但使用C++11 lambdas时,会出现以下情况:

typedef std::tuple<std::string, int, std::string> TUPLE;
std::map<int, TUPLE> m;

std::find_if(m.begin(), m.end(), [] (const std::pair<int, TUPLE>& v) {
    return v.second.get<1>() == "someString";
});
std::find_if(m.begin(), m.end(), 
    return boost::lambda::_1.second.second == "someString");