473,757 Members | 10,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

beg2 == end2 for find_first_of and find_end.

Can the 3rd and 4th arguments of find_first_of(b eg1, 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(v ecIcFile.begin( ), vecIcFile.end() , it,
it);
pos_ic_e = find_end(vecIcF ile.begin(), vecIcFile.end() , it, it);

But the following 2 calls are successful:

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

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

Jan 8 '07 #1
3 1860
"lovecreatesbea ...@gmail.com" <lo************ ***@gmail.comwr ote:
Can the 3rd and 4th arguments of find_first_of(b eg1, 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(v ecIcFile.begin( ), vecIcFile.end() , it,
it);
pos_ic_e = find_end(vecIcF ile.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(vec IcFile.begin(), vecIcFile.end() , *it);
pos_ic_e = upper_bound(vec IcFile.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>::it erator it1 =
find_first_of( vec.begin(), vec.end(), sub.begin(), sub.end() );

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

vector<int>::it erator 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.comwr ote:
Can the 3rd and 4th arguments of find_first_of(b eg1, 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(v ecIcFile.begin( ), vecIcFile.end() , it, it
+ 1);
I got an invalid iterator on following 2 calls:

pos_ic_b = find_first_of(v ecIcFile.begin( ), vecIcFile.end() , it,
it);
pos_ic_e = find_end(vecIcF ile.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(vec IcFile.begin(), vecIcFile.end() , *it);
pos_ic_e = upper_bound(vec IcFile.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.comwr ote:
"Daniel T. wrote:"
"lovecreatesbea ...@gmail.com" <lovecreatesbea ...@gmail.comwr ote:
Can the 3rd and 4th arguments of find_first_of(b eg1, 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(v ecIcFile.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
1863
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
4036
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 user command, argument; string::size_type index = string::npos; cout<<"\nThe Following are valid commands:\n"; cout<<"read_all <number> -- display entire mail header and body.\n";
0
2746
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 tool for breaking ties when a phonic call returns a bunch of possibilities. Also, I'm looking for someone that has a zip code file with alternate city names (the PO assigns whatever name is convenient to them), email me if you got something. ...
6
14905
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 searching for the first element in a vector of pairs. So now: typedef std::pair<int, int > int_pair; typedef std::vector<int_pair> vec_int_pair; int main() { vec_int_pair p;
1
1589
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
4211
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: ... // some control variables
6
17187
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 = "OneWord"; char* end1 = find_first_of(s1, s1 + strlen(s1), WS, WS + n_WS);
5
1463
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? Thanks in advance.
5
1578
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
9489
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
9298
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,...
1
9885
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
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
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
6562
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();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.