Link to home
Start Free TrialLog in
Avatar of Unimatrix_001
Unimatrix_001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Please check this simple function...

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

ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Unimatrix_001

ASKER

>>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...?
>> 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 ;)
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).
>> 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 :)
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! :)
>> 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

>>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
>> 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 :(
>>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
Cheer Uri, a pleasure as always :)
>> (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 :)
Ah okay - sorry, my bad... :)