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



 DEVELOP > c-Plus-Plus > how to find the first iterator that not equals to some specifiedvalue?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Leo jay"
Date: 16 Jan 2008 09:20:31 PM
Object: 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.
.

User: "William Xu"

Title: Re: how to find the first iterator that not equals to some specified value? 16 Jan 2008 10:32:19 PM
Leo jay <Python.LeoJay@gmail.com> writes:

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
.

User: "Barry"

Title: Re: how to find the first iterator that not equals to some specifiedvalue? 16 Jan 2008 10:13:57 PM
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<int> const& 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
.

User: "Salt_Peter"

Title: Re: how to find the first iterator that not equals to some specifiedvalue? 16 Jan 2008 10:46:18 PM
On Jan 16, 10:20 pm, Leo jay <Python.Leo...@gmail.com> 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.

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') );
}
.
User: "Leo jay"

Title: Re: how to find the first iterator that not equals to some specifiedvalue? 16 Jan 2008 11:18:33 PM
On Jan 17, 12:46 pm, Salt_Peter <pj_h...@yahoo.com> wrote:

On Jan 16, 10:20 pm, Leo jay <Python.Leo...@gmail.com> 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.


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.
.



  Page 1 of 1

1

 


Related Articles
How I free memory and return value from that memory area?
Re: Classes that refer to each other
calling virtual function that is hidden by inheritance
Creating an object that is read from an input stream.
sensing that an exception has occured
Ask about C program that convert NFA to DFA
Curiously recursive pattern-what is that???
Re: C/C++ compiler that will work with Atmel STK500
SQL oriented scripting language that can be executed from a C++ code
write aC++ program that would read from a CD and display information
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter
Find pairs that occur in two or more sets
What's the best way to hide the particular STL container that my class uses?
c++
Guaranteeing that a function does *not* exist
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER