473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to find the first iterator that not equals to some specifiedvalue?

dear all,

i know i can use std::find to find specified value in an iterator
range,
i'd like to know is there any way to find the first value that not
equals to the specified value?
just like string::find_first_not_of,
or do i have to write a for loop and check manually?

thanks in advance.
Jan 17 '08 #1
4 2213
Leo jay wrote:
dear all,

i know i can use std::find to find specified value in an iterator
range,
i'd like to know is there any way to find the first value that not
equals to the specified value?
just like string::find_first_not_of,
or do i have to write a for loop and check manually?

thanks in advance.
find_if: the predicate version of find

bool not_equal_to_1(int i) {
return i != 1;
}

void foo(std::vector<intconst& V) {
std::vector<int>::const_iterator pos =
std::find_if(V.begin(), V.end(), not_equal_to_1);
}

if you borrowing Boost.Lambda, it could be much simpler.

std::find_if(V.begin(), V.end(), _1 != 1);

--
Thanks
Barry
Jan 17 '08 #2
Leo jay <Py***********@gmail.comwrites:
i know i can use std::find to find specified value in an iterator
range,
i'd like to know is there any way to find the first value that not
equals to the specified value?
just like string::find_first_not_of,
or do i have to write a for loop and check manually?
Try std::find_if.

--
William

http://williamxu.net9.org
Jan 17 '08 #3
On Jan 16, 10:20 pm, Leo jay <Python.Leo...@gmail.comwrote:
dear all,

i know i can use std::find to find specified value in an iterator
range,
i'd like to know is there any way to find the first value that not
equals to the specified value?
just like string::find_first_not_of,
or do i have to write a for loop and check manually?

thanks in advance.
std::find_if and std::not_equal_to should do nicely.

assuming a vector of char:

#include <vector>
#include <algorithm // find_if
#include <functional // bind1st, not_equal_to

int main()
{
...
std::vector<char>::const_iterator it
= std::find_if( vc.begin(),
vc.end(),
std::bind1st (std::not_equal_to<char>(),
'a') );
}
Jan 17 '08 #4
On Jan 17, 12:46 pm, Salt_Peter <pj_h...@yahoo.comwrote:
On Jan 16, 10:20 pm, Leo jay <Python.Leo...@gmail.comwrote:
dear all,
i know i can use std::find to find specified value in an iterator
range,
i'd like to know is there any way to find the first value that not
equals to the specified value?
just like string::find_first_not_of,
or do i have to write a for loop and check manually?
thanks in advance.

std::find_if and std::not_equal_to should do nicely.

assuming a vector of char:

#include <vector>
#include <algorithm // find_if
#include <functional // bind1st, not_equal_to

int main()
{
...
std::vector<char>::const_iterator it
= std::find_if( vc.begin(),
vc.end(),
std::bind1st (std::not_equal_to<char>(),
'a') );

}
thanks, that's what i'm looking for.
Jan 17 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dennis | last post by:
Hi I'm trying to implement a vector of vectors where find can be used to find a vector<double> in the vectors of vectors, that is hard to understand i guess. What I mean is that I got a vector...
3
by: Old Wolf | last post by:
In the documentation for std::find, it says: find returns the first iterator i in the range [first, last) for which the following condition holds: *i == value. However in my compiler's...
22
by: mail.zhf | last post by:
if have two char use equality, out first. example: char str = "gbdfssdffss"; out is: f.
4
by: Arjen | last post by:
Hi, I have a class with some attributes. For example class person with name as attribute. I have add multiple persons in an arraylist. Now I need a function to get/find a person by the name...
12
by: Rubbrecht Philippe | last post by:
Hi there, According to documentation I read the ArrayList.IndexOf method uses the Object.Equals method to loop through the items in its list and locate the first index of an item that returns...
18
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
18
by: ma740988 | last post by:
Trying to get more acclimated with the use of function objects. As part of my test, consider: # include <vector> # include <iostream> # include <algorithm> #include <stdexcept> #include...
5
by: Draw | last post by:
Hi All, Just a thought, about the find() algorithm in the C++ STL. I read that the find algorithm can take a range of iterators. If it does not find the element it is looking for in that range...
16
by: mailforpr | last post by:
How do I do that? The thing is, the only information I have about the iterator is the iterator itself. No container it is belonging to or anything. Like template<Iteratorvoid...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.