General
This specification defines several functions and associated types that support the use of ranges with IOStreams.
Header synopsis
namespace std {
template<class Range, class Iterator, class Behaviour>
RangeInputOperation input(Range& range, Iterator i, Behaviour behaviour);
template<class Range, class Behaviour>
RangeInputOperation input(Range& range, Behaviour behaviour);
template<class Range>
RangeInputOperation overwrite(Range& range);
template<class Range>
RangeInputOperation back_insert(Range& range);
template<class Range>
RangeInputOperation back_insert_n(Range& range, size_t count);
template<class Range>
RangeInputOperation front_insert(Range& range);
template<class Range>
RangeInputOperation front_insert_n(Range& range, size_t count);
template<class Range, class Iterator>
RangeInputOperation insert(Range& range, Iterator pos);
template<class Range, class Iterator>
RangeInputOperation insert_n(Range& range, Iterator pos, size_t count);
template<class Range>
RangeOutputOperation write_all(Range&& range);
template<class Range, class Delimiter>
RangeOutputOperation write_all(Range&& range, Delimiter&& delim);
}
Requirements
Range I/O functions are functions that take a range, possibly with other arguments, and return range I/O operation objects that can be used in IOStreams insertion or extraction expressions to perform input or output using the range.
Range I/O functions and range I/O operation objects must not copy the provided range.
For ranges given as an lvalue, they must keep a reference or pointer to the range.
For ranges given as an rvalue, they must move the range into a locallyowned variable.
Behaviour is undefined if the range I/O operation object is used after the range goes out of scope or is modified by any other operation.
Range I/O operation objects must be MoveConstructible, MoveAssignable, and Destructible.
The range I/O operation objects returned by range I/O functions should be usable with input or output streams (as applicable) either by lvalue reference or rvalue reference.
This is to support the following two use cases (r
is a Range):
cin >> back_insert(r);
and
auto b = back_insert(r);
cin >> b;
All input and output operations should set the stream width value to 0
immediately before returning.
Output requirements
Range output functions return a range output operation object that can be used with stream insertion operations by lvalue or rvalue.
The output operation object type satisfies the requirements shown in the table below.
In that table and throughout this section:

p
is an instance of a range output operation type returned by a range output function;

r
is a range type (that is, a type that can be used as the argument of a range for
loop);

It
is the type returned by begin(r)
;

out
is a nonconst
lvalue reference to an instance of basic_ostream
.
Expression 
Return type 
Pre/postcondition 
p.count 
size_t 
Equal to the number of values successfully written to out .
Initially zero.

p.next 
It 
An iterator to the next position in r to be read.
This will be begin(r) before any output operations, and end(r) after any completely successful output operations.

Any formatting that would apply to the output of a single value type of the range must be applied to every element of the range.
Output operations must set the stream width to zero immediately before returning.
After every element insertion, the state of the output stream is checked by the stream object’s conversion to bool
, and if it is false
, the operation ends immediately.
When the range is empty, an output operation should attempt an unformatted write of out.width()
copies of out.fill()
to out
, then call out.width(0)
.