Is the comparison of begin() and end() iterators of two std::spans that point to the same memory well defined?
#include <span>
#include <cassert>
int main() {
int arr[5]{1,2,3,4,5};
std::span s1{arr};
std::span s2{arr};
assert(s1.begin() == s2.begin());
assert(s1.end() == s2.end());
assert(s1.begin() + s1.size() == s2.end());
}
All asserts pass on all implementations of std::span so far, but is there anything I may be missing that makes this a bug, e.g., UB?
For context, this can arise if you have a class that tries to hide its internals with a span.
class some_class
{
public:
std::span<int> vec_view() { return vec; }
private:
std::vector<int> vec;
};
int main() {
some_class c;
std::for_each(c.vec_view().begin(), c.vec_view().end(), [](auto&){});
}
This is related to Does C++ allow comparison between std::span::iterators when one span is a subspan of the other?, but this question is not about a std::subspan, and moreover the std::span version also passes MSVC asserts, unlike the version with the std::subspan.
std::spanreally a container in the same sense as e.g.std::vector?&(*s1.begin()) == &(*s2.begin())end()orbegin()of empty container?