473,322 Members | 1,493 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,322 software developers and data experts.

beg2 == end2 for find_first_of and find_end.

Can the 3rd and 4th arguments of find_first_of(beg1, end1, beg2, end2)
and find_end(beg1, end1, beg2, end2) be the same? I got an invalid
iterator on following 2 calls:

pos_ic_b = find_first_of(vecIcFile.begin(), vecIcFile.end(), it,
it);
pos_ic_e = find_end(vecIcFile.begin(), vecIcFile.end(), it, it);

But the following 2 calls are successful:

pos_ic_b = lower_bound(vecIcFile.begin(), vecIcFile.end(), *it);
pos_ic_e = upper_bound(vecIcFile.begin(), vecIcFile.end(), *it);

Can't these two pairs of functions do the same task?

Jan 8 '07 #1
3 1840
"lovecreatesbea...@gmail.com" <lo***************@gmail.comwrote:
Can the 3rd and 4th arguments of find_first_of(beg1, end1, beg2, end2)
and find_end(beg1, end1, beg2, end2) be the same?
Yes, but in that case the function will always return a value equal to
end1, because the range of things you are searching for is empty.
I got an invalid iterator on following 2 calls:

pos_ic_b = find_first_of(vecIcFile.begin(), vecIcFile.end(), it,
it);
pos_ic_e = find_end(vecIcFile.begin(), vecIcFile.end(), it, it);
pos_ic_b should end up equaling veclcFile.end(). Same with pos_ic_e.
But the following 2 calls are successful:

pos_ic_b = lower_bound(vecIcFile.begin(), vecIcFile.end(), *it);
pos_ic_e = upper_bound(vecIcFile.begin(), vecIcFile.end(), *it);
lower_bound assumes a sorted range.
Can't these two pairs of functions do the same task?
find_first_of and lower_bound will "do the same task" only if the third
and fourth arguments define a range that contains only one element value.

For example:

void fn( vector<int>& vec, int i )
{
vector<Tsub( 1, i ); // could be (2, i) or (3, i) etc...
vector<int>::iterator it1 =
find_first_of( vec.begin(), vec.end(), sub.begin(), sub.end() );

vector<int>::iterator it2 = find( vec.begin(), vec.end(), i );

vector<int>::iterator it3 = lower_bound( vec.begin(), vec.end(), i );

assert( it1 == it2 );

if ( is_sorted( vec.begin(), vec.end() )
assert( it1 == it3 );
}
Jan 8 '07 #2

"Daniel T. wrote:"
"lovecreatesbea...@gmail.com" <lo***************@gmail.comwrote:
Can the 3rd and 4th arguments of find_first_of(beg1, end1, beg2, end2)
and find_end(beg1, end1, beg2, end2) be the same?

Yes, but in that case the function will always return a value equal to
end1, because the range of things you are searching for is empty.
Thank you.

I write it as following to specify a single element as the second
range, is it right?

pos_ic_b = find_first_of(vecIcFile.begin(), vecIcFile.end(), it, it
+ 1);
I got an invalid iterator on following 2 calls:

pos_ic_b = find_first_of(vecIcFile.begin(), vecIcFile.end(), it,
it);
pos_ic_e = find_end(vecIcFile.begin(), vecIcFile.end(), it, it);

pos_ic_b should end up equaling veclcFile.end(). Same with pos_ic_e.
But the following 2 calls are successful:

pos_ic_b = lower_bound(vecIcFile.begin(), vecIcFile.end(), *it);
pos_ic_e = upper_bound(vecIcFile.begin(), vecIcFile.end(), *it);

lower_bound assumes a sorted range.
The elements of the vectors in my code are type of structure. They have
customized sort criteria. I overloaded operator < () for the structure
type.

Jan 8 '07 #3
On Jan 8, 8:01 am, "lovecreatesbea...@gmail.com"
<lovecreatesbea...@gmail.comwrote:
"Daniel T. wrote:"
"lovecreatesbea...@gmail.com" <lovecreatesbea...@gmail.comwrote:
Can the 3rd and 4th arguments of find_first_of(beg1, end1, beg2, end2)
and find_end(beg1, end1, beg2, end2) be the same?
Yes, but in that case the function will always return a value equal to
end1, because the range of things you are searching for is empty.Thank you.

I write it as following to specify a single element as the second
range, is it right?

pos_ic_b = find_first_of(vecIcFile.begin(), vecIcFile.end(), it, it
+ 1);
Yes, that should work as long as 'it' is a random access iterator (it
won't compile otherwise).

--
Erik Wikström

Jan 8 '07 #4

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

Similar topics

2
by: Rex_chaos | last post by:
Hi all, suppose A is an array. With the help of template function find_first_of and find_end, I got two desired elements of array. How can I tell the distance between these two elements?
4
by: Christopher | last post by:
I am using std::string to parse a command given by the user, I don't understand why the following snippet is not working as expected. string buffer, // store commands from...
0
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful...
6
by: ma740988 | last post by:
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...
1
by: Allerdyce.John | last post by:
I have my source string like this: As i step thru the debugger, I can't understand why namePosStart is 2 namePosEnd is 15 I expect: namePosStart is 9 namePosStart is 11
2
by: scottys0 | last post by:
Hi everyboy, I'm working in an IOC-IBM (IBM open class) replamecent library. the code seens confused but , no, isn't. #define INumber long class IString : public std::string { private:...
6
by: tingjun.li | last post by:
There is a demo program: ------------------------------------------------- const char* WS = " \t\n"; const int n_WS = strlen(WS); char* s1 = "This sentence contains five words."; char* s2 =...
5
by: johnhjohn | last post by:
For some reason it seems as though firefox doesn't like the else statement. I use it often but it has been giving me a lot of troudlbe lately. Does anyone have any ideas of what I should do? ...
5
by: er | last post by:
hi, is anyone aware of a library that generalizes transform, for_each? e.g. transform( vec1.begin(), vec1.end(), vec2.begin(), vec3.begin(),
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.