A "Singular Iterator" is defined as an:
iterators that are not associated with any sequence. A null pointer, as well as a default-constructed pointer (holding an indeterminate value) is singular
My question 1 would be: Is a default constructed iterator considered a "Singular Iterator"?
Secondly, I have been told here that:
Results of most expressions are undefined for singular values; the only exceptions are destroying an iterator that holds a singular value, the assignment of a non-singular value to an iterator that holds a singular value, and, for iterators that satisfy the DefaultConstructible requirements, using a value-initialized iterator as the source of a copy or move operation.
Question 2 is: Does working with a result that is "undefined" constitute Undefined Behavior? It would seem that if that were true this would be Undefined Behavior:
void* foo = nullptr;
auto bar = foo;
But it runs fine.
My deeper motivation for asking this question is in the case where I have a struct like this:
struct Foo {
vector<int*>::const_iterator;
};
I want to know if it is undefined behavior to do this, where assigned
is a value constructed Foo
object:
Foo unasigned;
assigned = unassigned;
If the answers to questions 1 and 2 are "yes" then by invoking the default assignment operator I am introducing undefined behavior :(
vector<int*>::const_iterator foo;
is what I'm referring to when I say "default constructed iterator". – Fleetvector<int*>::const_iterator
, it's an implementation-defined type, and you can't assume that it does anything more than what the standard requires. – Ornate