Solved

Please check this simple function...

Posted on 2008-06-16
14
162 Views
Last Modified: 2010-04-01
As per subject...

Thanks,
Uni
/*********************************************************************************
This returns a corrected iterator, ensuring that if we want to increase
aInitialIterator by aIncreaseBy, we don't go out of the highest bounds of
aHaystack.
*********************************************************************************/
vector<BIT>::iterator getCorrectedHighIterator(vector<BIT> &aHaystack, const vector<BIT>::iterator &aInitialIterator, const unsigned int aIncreaseBy){
	if(aHaystack.end()-aInitialIterator<aIncreaseBy)
		return aHaystack.end();
	return(aInitialIterator+aIncreaseBy);
}
/********************************************************************************/

Open in new window

0
Comment
Question by:Unimatrix_001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 60 total points
ID: 21793457
Looks good to me.

Do you experience problems with it ?
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 40 total points
ID: 21793472
Being picky now: This will probably fail in a nasty way if the iterator is not for the same vector as that passed in :)
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21793501
>>Do you experience problems with it ?
None yet, although I thought I'd tested my other question code fully but found that to cause problems! :D

>>Being picky now: This will probably fail in a nasty way if the iterator is not for the same vector as that passed in :)
Hehe, that's not a problem - but thanks anyways.

Is a 50 50 split with you two okay - I got the two e-mails at exactly the same time...?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Infinity08
ID: 21793525
>> Is a 50 50 split with you two okay

Fine by me :)


I have been meaning to make the comment evilrix made a few times before, but I assumed you'd be aware of that ;)
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21793524
Also, why not template it, then it'd be generic for all container types, no? Also, I'd change it so it only works with iterators and doesn't worry about the container... it doesn't need to doe it? end() can be passed in as another iterator. This is normally how STL algos work (just with iterators).
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21793535
>> Is a 50 50 split with you two okay - I got the two e-mails at exactly the same time...?
Whatever you think best Uri  -- that works for me... although I don't feel like either of us really earned anything here :)
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21793551
I've increse points to 100, doing a 60/40 split to Infinity (taking him at his word of trying a few times before the comment came though ;)

Ah the template is too much hassle for this - it is only a very small program, but I guess in the long run if I was going to make heavy use of it I would agree.

>>although I don't feel like either of us really earned anything here :)
You've put my mind at ease, that's enough for me! :)
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21793590
>> Ah the template is too much hassle for this
Eh?
template <typename T>
typename T::iterator getCorrectedHighIterator(
	T &aHaystack,
	const typename T::iterator &aInitialIterator,
	const unsigned int aIncreaseBy
	)
{
	if(aHaystack.end()-aInitialIterator<aIncreaseBy)
		return aHaystack.end();
	return(aInitialIterator+aIncreaseBy);
}

Open in new window

0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21793600
>>Eh?
Meh, I'm not very good at templates... besides you're a sage! You can just think something near a computer and it happens! :D
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21793613
>> Meh, I'm not very good at templates...
Sure you are -- you just don't know it yet :)

>> besides you're a sage!
I prefer sage and onion myself :)

>> You can just think something near a computer and it happens! :D
I tried this, I thought of lovely dancing girls -- nothing :(
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21793663
>>Sure you are -- you just don't know it yet :)
Maybe one day... :)

>>I tried this, I thought of lovely dancing girls -- nothing :(
Hehehe, maybe they don't like sage and onion, try seperately... :D

Cheers mate. :)
Uni
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21793681
Cheer Uri, a pleasure as always :)
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21793744
>> (taking him at his word of trying a few times before the comment came though ;)

Ah no, that was not what I intended ... I meant that I thought about making the same comment evilrix did a few times before (in your previous questions), but I never did. I'm glad evilrix did :)
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21793764
Ah okay - sorry, my bad... :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question