c++ - use std::find to find a std::tuple in a std::vector -


so have vector of tuple coordinates made following code:

vector<tuple<int, int>> coordinates; (int = 0; <  7; i++){    (int j = 0; j < 6; j++){       coordinates.push_back(make_tuple(i, j));    } } 

i'm trying fill board either 'x', 'o', or '.' following:

void displayboard(vector<tuple<int,int>>& board, vector<tuple<int,int>>& p1, vector<tuple<int,int>>& p2){  // prints out board   cout << "    b   c   d   e   f   g\n";  // top row   (int = 1; < 43; i++){     if (i % 7 == 0) {       if (find(p1.begin(), p1.end(), board[i])) cout << "| x |\n";       else if (find(p2.begin(), p2.end(), board[i])) cout << "| o |\n";       else cout << "| . |\n";     } else {       if (find(p1.begin(), p1.end(), board[i])) cout << "| x ";       else if (find(p2.begin(), p2.end(), board[i])) cout << "| o ";       else cout << "| . ";     }   } } 

my int main looks follows:

int main() {   vector<tuple<int, int>> coordinates;   (int = 0; <  7; i++){     (int j = 0; j < 6; j++){       coordinates.push_back(make_tuple(i, j));     }   }   vector<tuple<int,int>> p1 = {make_tuple(0,1)};   vector<tuple<int,int>> p2 = {make_tuple(3,1)};   displayboard(coordinates, p1, p2);   return 0; } 

i used (0,1) , (3,1) test coordinates see if code run. long story short, wanted use std::find find if tuple coordinate chosen either p1 or p2 , format outputted string accordingly. if if std::find_if(p1.begin(), p1.end(), make_tuple(2,2)) true put fill cell 'x' example. problem following error when compiling:

error: not convert ‘std::find<__gnu_cxx::__normal_iterator<std::tuple<int, int>*, std::vector<std::tuple<int , int> > >, std::tuple<int, int> >((& p2)->std::vector<_tp, _alloc>::begin<std::tuple<int, int>, std::allocator<std::tuple<int, int> > >(), (& p2)->s td::vector<_tp, _alloc>::end<std::tuple<int, int>, std::allocator<std::tuple<int, int> > >(), (*(const std::tuple<int, int>*)(& board)->std::vector<_ tp, _alloc>::operator[]<std::tuple<int, int>, std::allocator<std::tuple<int, int> > >(((std::vector<std::tuple<int, int> >::size_type)i))))’ ‘__ gnu_cxx::__normal_iterator<std::tuple<int, int>*, std::vector<std::tuple<int, int> > >’ ‘bool’

so question if can use std::find_if find std::tuple in std::vector. , if not how can find tuple in vector.

note: included: iostream, string, tuple, vector, , algorithm , using namespace std.

your issue not searching tuple in vector. search fine.

your issue std::find returns either iterator found sequence member, or ending iterator value.

your code assumes std::find() returns bool indication value has been found. not true. std::find() returns iterator. either iterator found value, or ending iterator value.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -