For example, it this expression valid in semantic?
container.begin() == container.begin();
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With