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]
std::vector : is this allowed? [sorted]
Is this allowed?
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.
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.
Quote:Original post by Illco*grin* - let's not [grin]. Reading properly before posting always helps [wink].
LOL Andrew -- ok good point indeed! Saw your first post though but let's not talk about it.
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.
The only exception is if "a" and "b" reference the same instance but that is rarely going to happen.
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)
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement