Are standard container iterators DefaultConstructible?

Is it well formed?

int main() {
    std::deque< int >::iterator x; // Or any container.
}

Bonus questions:

  • What about a auto y = x;potential copy of an uninitialized state?
  • What about โ€ฆ x = {};, which requires an implicit default constructor?
  • What about x == yif both are initialized with a value (not initialized by default, as shown)?
+4
source share
2 answers

Depends on the Iterator concept you are testing.

Iterator, , , , CopyConstructible, CopyAssignable Destructible. (ยง 24.2.2/2)

( std::forward_list, ). ForwardIterator, InputIterator ( ).

ForwardIterator :

X ,

- X (24.2.3),

- X DefaultConstructible (17.6.3.1),

ยง 24.2.5/1 N3376

, .

ยง 24.2, cppreference

+8

, , , .

ยง24.2.2 [iterator.iterators] (n3485), Iterator () DefaultConstructible. , ยง24.2.3 [input.iterators] $24.2.4 [output.iterators], InputIterator OutputIterator.

ยง24.2.5 [forward.iterators], :

1/ X ,

  • X (24.2.3),
  • X DefaultConstructible (17.6.3.1) [...]

, ForwardIterator, .

+5

All Articles