|
-
January 12th, 2006, 07:23 PM
#5
Re: How to convert from a const iterator to a non-const iterator?
 Originally Posted by NMTop40
Why are you writing your own loop? What is wrong with std::find_if ?
Of course, it requires a functor. You can write one thus:
Code:
class node_name_is
{
std::string searchName; // can also be const std::string &
public:
node_name_is( const std::string & sn ) : searchName( sn )
{
}
bool operator() ( graph::node * pNode )
{
return searchName == pNode->name;
}
};
list<graph::node*> const_iterator it =
std::find_if( nodelist.begin(), nodelist.end(),
node_name_is( node_name ) );
// check if it= nodelist.end()
Thanks. I couldn't find that method here, so I didn't know that it existed.
 Originally Posted by NMTop40
(I don't suggest you call your list list, although as long as you don't force namespace std in, there is no name-clash).
That's not one of my better examples of coding skills .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|