# std::vector : is this allowed? [sorted]

This topic is 4829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is this allowed?
bool some_func (vector<int> &a, vector<int> &b)
{
return a.end() == b.begin();
}

I was wondering is this is allowed since a.end() is past-the-end and might therefore equal b.begin(). If it isn't allowed is it permitted for any other container type? [Edited by - dmatter on May 31, 2005 11:29:51 AM]

##### Share on other sites
No. Don't do that - iterators from two different containers are not comparable.

##### Share on other sites
wrong
It is allowed but what would you expect it to do? By definition a.end() refers to an invalid element and hence would only equal b.begin() if b is the empty vector. So basically, I think, this is a complicated way of writing b.empty().
end

Greetz,

Illco

LOL Andrew -- ok good point indeed! Saw your first post though but let's not talk about it.

##### Share on other sites
Quote:
 Original post by IllcoLOL Andrew -- ok good point indeed! Saw your first post though but let's not talk about it.
*grin* - let's not [grin]. Reading properly before posting always helps [wink].

##### Share on other sites
It's syntactic correct but nonsensical, for any container even if a is empty it may still return false as it depends on implementation which you should never rely on, in any case they are distinct and should be treated as distinct.

The only exception is if "a" and "b" reference the same instance but that is rarely going to happen.

##### Share on other sites
The big question here is, why!

Why in gods name do you want to do a thing like that?

##### Share on other sites
sorry for the delay & thanks for the responces.

I know it is a nonsensical thing to do and the problem was that I had a function that relied on the assumption that the end of one container != the beginning of then next.

I couldn't understand why I was being forced to actually write code made assumptions like that (I knew that it was dumb but it was the only way for the function to do its job) however the problem was that I was passing it the wrong iterator in the first place so now its not a problem.

Thanx anyway (quite interesting to know actually)

1. 1
2. 2
JoeJ
20
3. 3
4. 4
frob
12
5. 5

• 13
• 18
• 13
• 20
• 13
• ### Forum Statistics

• Total Topics
632194
• Total Posts
3004681

×