Apr 10, 2017 at 8:30am Apr 10, 2017 at 8:30am UTC
I am using tuple in lambda as below:
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
int main()
{
int key = 10;
vector<tuple<int, int>> v;
v.reserve(10);
v[0] = std::make_tuple(10,11);
v[1] = std::make_tuple(20,21);
if(v.end() != std::find(v.begin(), v.end(),[key](std::tuple<int,int> t) {return t.get<0> == key;}))
{
cout<<"FOUND\n";
}
else
{
cout<<"NOT FOUND\n";
}
}
I am getting error:
g++ -std=c++0x d.cpp -o d
d.cpp: In function ‘int main()’:
d.cpp:19: error: expected primary-expression before ‘[’ token
d.cpp:19: error: expected primary-expression before ‘t’
Apr 10, 2017 at 8:41am Apr 10, 2017 at 8:41am UTC
A tiny syntax error: you didn't call get<0>()
:
[key](std::tuple<int ,int > t) {return t.get<0>() == key;}
Last edited on Apr 10, 2017 at 8:42am Apr 10, 2017 at 8:42am UTC
Apr 10, 2017 at 12:52pm Apr 10, 2017 at 12:52pm UTC
coder777: yes, of course, you're spot on!