• Advertisement
Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by Illco
LOL 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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
The big question here is, why!

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

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement