Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/OutputIterator"

From cppreference.com
< cpp‎ | named req
m (more details for the invalidation on assignment rule)
m (~)
Line 24: Line 24:
 
!Expression||Return||Equivalent expression||Post-conditions||Notes
 
!Expression||Return||Equivalent expression||Post-conditions||Notes
 
|-
 
|-
|{{c|*r {{=}} o}}|| || || {{tt|r}} is incrementable || {{tt|r}}, along with any copy of {{tt|r}} is not required to be dereferencable after this operation: it may not be possible to write through the same iterator value twice
+
|{{c|*r {{=}} o}}|| || || {{tt|r}} is incrementable || {{tt|r}} (along with all copies of {{tt|r}}) is not required to be dereferencable after this operation: it may not be possible to write through the same iterator value twice
 
|-
 
|-
 
|{{c|++r}}||{{c|X&}}||  
 
|{{c|++r}}||{{c|X&}}||  
Line 39: Line 39:
 
|{{c|*r++ {{=}} o}} || ||
 
|{{c|*r++ {{=}} o}} || ||
 
| {{tt|r}} is incrementable
 
| {{tt|r}} is incrementable
| {{tt|r}} is not required to be dereferencable after this operation.
+
| {{tt|r}} (along with all copies of {{tt|r}}) is not required to be dereferencable after this operation.
 
|}
 
|}
  
Line 47: Line 47:
 
Equality and inequality may not be defined for output iterators.
 
Equality and inequality may not be defined for output iterators.
  
Assignment through the same value of the output iterator happens only once: algorithms on output iterators must be single-pass algorithms.
+
Assignment through the same value of an output iterator happens only once: algorithms on output iterators must be single-pass algorithms.
  
 
Examples of output iterators that are not forward iterators are {{lc|std::ostream_iterator}} and {{lc|std::ostreambuf_iterator}}.
 
Examples of output iterators that are not forward iterators are {{lc|std::ostream_iterator}} and {{lc|std::ostreambuf_iterator}}.

Revision as of 05:39, 22 August 2014

Template:cpp/concept/title Template:cpp/concept/navbar

An OutputIterator is an Template:concept that can write to the pointed-to element.

An example of a type that implements OutputIterator is std::ostream_iterator.

When Template:concept, Template:concept, or Template:concept satisfies the Template:concept requirements in addition to its own requirements, it is described as mutable.

Requirements

The type X satisfies OutputIterator if

And, given

  • o a value of some type that is writable to the output iterator
  • r an lvalue of type X,

The following expressions must be valid and have their specified effects

Expression Return Equivalent expression Post-conditions Notes
*r = o r is incrementable r (along with all copies of r) is not required to be dereferencable after this operation: it may not be possible to write through the same iterator value twice
++r X& &r == &++r, r is incrementable r is not required to be dereferencable after this operation.
r++ convertible to const X& X temp = r;

++r;
return temp;

r is incrementable
*r++ = o r is incrementable r (along with all copies of r) is not required to be dereferencable after this operation.

Notes

The only valid use of operator* with an output iterator is on the left of an assignment.

Equality and inequality may not be defined for output iterators.

Assignment through the same value of an output iterator happens only once: algorithms on output iterators must be single-pass algorithms.

Examples of output iterators that are not forward iterators are std::ostream_iterator and std::ostreambuf_iterator.

See also