在元组向量中找到特定的元组元素? [英] Find a specific tuple element in a vector of tuples?

查看:94
本文介绍了在元组向量中找到特定的元组元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在元组向量中查找元组元素时遇到问题。

I am having an issue with finding a tuple element, in a vector of tuples.

我有一个 vector< tuple< int,int,int,int>> 找出向量中 get< 0>(向量)= 0 的位置。我需要该位置,因为我也需要从该位置的元组中提取其他值。

I have a vector<tuple<int,int,int,int>> in which I need to find the position in the vector where get<0>(vector) = 0. I need the position, as I need to extract the other values from the tuple in that position as well.

get< 0> 的值是唯一的,并且在向量中只会出现一次。

The value of get<0> is unique and will only occur once in the vector.

我该怎么做?

推荐答案

您应该使用 std :: find_if 算法;

std::vector<std::tuple<int,int,int,int>> v =
    {{0,1,2,3},{1,2,3,4},{2,3,4,5}};

auto it = std::find_if(v.begin(), v.end(), [](const std::tuple<int,int,int,int>& e) {return std::get<0>(e) == 0;});
if (it != v.end()) {
  std::cout << "Found" << std::endl;
}

这篇关于在元组向量中找到特定的元组元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆