简体   繁体   English

C ++在std :: set的嵌套对中搜索对象

[英]C++ Searching object in nested pair of an std::set

I have an STL set of type: 我有一组STL类型:

std::set< std::pair< double, std::pair< unsigned, vector< unsigned > > > > X

I know I could make things simpler by changing my data structure but that's not an option here for me. 我知道我可以通过更改数据结构来简化事情,但这对我来说不是一个选择。

How can I search for an element of type unsigned only in the first elements of the inner pair in my set? 如何仅在集合中内部对的前unsigned元素中搜索unsigned类型的元素?

I tried the following approach, but doesn't work. 我尝试了以下方法,但不起作用。

auto it = std::find_if(X.begin(), X.end(), [value_searching]
(const std::pair<double, std::pair< unsigned, vector< unsigned > >& elem) {
return elem->second.first == value_searching
        });

You need to use . 您需要使用. instead of -> , because elem is a reference, not a pointer, to a pair . 而不是-> ,因为elempair的引用,而不是指针。

auto it = std::find_if(X.begin(), X.end(), [value](auto& elem) {
  return elem.second.first == value;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM