M
ma740988
Oh what fun it is to get acclimated with the various containers and
algorithms.. I'm trying to determine if I could use find/find_first_of
algorithms to achieve the same object of a for loop when searching for
the first element in a vector of pairs. So now:
typedef std:
air<int, int > int_pair;
typedef std::vector<int_pair> vec_int_pair;
int main()
{
vec_int_pair p;
p.push_back(std::make_pair( 5, 6));
p.push_back(std::make_pair( 5, 7));
for (vec_int_pair::iterator it = p.begin();
it != p.end();
++it)
{
if (it->first = 5)
p.erase(it);
}
// now lets try the same thing with find and/or find_first_of
//it = find ( p.begin(), p.end(), 5); -- 1
//it = find_first_of ( p.begin(), p.end(), 5); -- 2
// validate that we only have 5, 7
cout << p.size() << endl;
for (vec_int_pair::iterator it = p.begin();
it != p.end();
++it)
{
cout << it->first << endl;
cout << it->second << endl;
}
}
The lines marked --1 and --2 are of interest. My guess is I would
need a function object, but I'm not sure if that even makes sense?
Sample source greatly appreaciated.
Thanks.
algorithms.. I'm trying to determine if I could use find/find_first_of
algorithms to achieve the same object of a for loop when searching for
the first element in a vector of pairs. So now:
typedef std:
typedef std::vector<int_pair> vec_int_pair;
int main()
{
vec_int_pair p;
p.push_back(std::make_pair( 5, 6));
p.push_back(std::make_pair( 5, 7));
for (vec_int_pair::iterator it = p.begin();
it != p.end();
++it)
{
if (it->first = 5)
p.erase(it);
}
// now lets try the same thing with find and/or find_first_of
//it = find ( p.begin(), p.end(), 5); -- 1
//it = find_first_of ( p.begin(), p.end(), 5); -- 2
// validate that we only have 5, 7
cout << p.size() << endl;
for (vec_int_pair::iterator it = p.begin();
it != p.end();
++it)
{
cout << it->first << endl;
cout << it->second << endl;
}
}
The lines marked --1 and --2 are of interest. My guess is I would
need a function object, but I'm not sure if that even makes sense?
Sample source greatly appreaciated.
Thanks.