For example, it this expression valid in semantic?
container.begin() == container.begin();
For example, it this expression valid in semantic?
container.begin() == container.begin();
Yes, begin()
will return the same iterator given a container instance, unless you change the container in some way (end()
has this property as well). For example, std::vector::push_back()
may cause the array to be reallocated to accommodate new elements.
Yes, so long as neither iterator has been invalidated.
For example, the following would not be valid:
std::deque<int> d;
std::deque<int> begin1 = d.begin();
d.push_front(42); // invalidates begin1!
std::deque<int> begin2 = d.begin();
assert(begin1 == begin2); // wrong; you can't use begin1 anymore.