473,659 Members | 2,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_fi rst_not_of,
or do i have to write a for loop and check manually?

thanks in advance.
Jan 17 '08 #1
4 2228
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_fi rst_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_iterat or 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_fi rst_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_fi rst_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<cha r>::const_itera tor 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_fi rst_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<cha r>::const_itera tor 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
2259
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 foo containing vectors of the size 3. I then want to compare a vector<double> of size 3 (coord) with foo to find a sequence of elements in foo that equals coord. However, when I try this it returns when just one of the element of coord equals one...
3
1809
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 headers the implementation is: template <class InputIterator, class T> InputIterator find (InputIterator first, InputIterator last, const T& value)
22
3837
by: mail.zhf | last post by:
if have two char use equality, out first. example: char str = "gbdfssdffss"; out is: f.
4
12983
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 attribute. This function returns the index or the object. I can do this with a foreach statement. I think there are better solutions,
12
6730
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 True. Therefore, overriding the Equals method in the class definition of the items I put in the ArrayList should make the IndexOf method use my version of the Equals method?!
18
38227
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
18
7202
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 <bitset> using std::vector;
5
2573
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 it returns the iterator to the last element in the range, not to the last element in the container, to the last element in the range. That being said, how can we tell if find() has been successful in finding the element we need? Its easy when we...
16
2576
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 totally_isolated(Iterator& it) { //how do I find out if it points to the end node? }
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.