Skip to content

Commit 5ec9daa

Browse files
CaseyCarterzygoloid
authored andcommitted
P0738R2 I Stream, You Stream, We All Stream for istream_iterator
Fixes #2697.
1 parent 52f8ba7 commit 5ec9daa

File tree

1 file changed

+43
-70
lines changed

1 file changed

+43
-70
lines changed

source/iterators.tex

Lines changed: 43 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5569,51 +5569,9 @@
55695569

55705570
\pnum
55715571
\indexlibrary{\idxcode{istream_iterator}}%
5572-
The class template
5573-
\tcode{istream_iterator}
5574-
is an input iterator\iref{input.iterators} that
5575-
reads (using
5576-
\tcode{operator>>})
5577-
successive elements from the input stream for which it was constructed.
5578-
After it is constructed, and every time
5579-
\tcode{++}
5580-
is used, the iterator reads and stores a value of
5581-
\tcode{T}.
5582-
If the iterator fails to read and store a value of \tcode{T}
5583-
(\tcode{fail()}
5584-
on the stream returns
5585-
\tcode{true}),
5586-
the iterator becomes equal to the
5587-
\term{end-of-stream}
5588-
iterator value.
5589-
The constructor with no arguments
5590-
\tcode{istream_iterator()}
5591-
always constructs
5592-
an end-of-stream input iterator object, which is the only legitimate iterator to be used
5593-
for the end condition.
5594-
The result of
5595-
\tcode{operator*}
5596-
on an end-of-stream iterator is not defined.
5597-
For any other iterator value a
5598-
\tcode{const T\&}
5599-
is returned.
5600-
The result of
5601-
\tcode{operator->}
5602-
on an end-of-stream iterator is not defined.
5603-
For any other iterator value a
5604-
\tcode{const T*}
5605-
is returned.
5606-
The behavior of a program that applies \tcode{operator++()} to an end-of-stream
5607-
iterator is undefined.
5608-
It is impossible to store things into istream iterators.
5609-
The type \tcode{T} shall satisfy the \oldconcept{DefaultConstructible},
5610-
\oldconcept{CopyConstructible}, and \oldconcept{CopyAssignable} requirements.
5611-
5612-
\pnum
5613-
Two end-of-stream iterators are always equal.
5614-
An end-of-stream iterator is not
5615-
equal to a non-end-of-stream iterator.
5616-
Two non-end-of-stream iterators are equal when they are constructed from the same stream.
5572+
The class template \tcode{istream_iterator}
5573+
is an input iterator\iref{input.iterators} that reads successive elements
5574+
from the input stream for which it was constructed.
56175575

56185576
\begin{codeblock}
56195577
namespace std {
@@ -5654,6 +5612,10 @@
56545612
}
56555613
\end{codeblock}
56565614

5615+
\pnum
5616+
The type \tcode{T} shall meet the \oldconcept{DefaultConstructible},
5617+
\oldconcept{CopyConstructible}, and \oldconcept{CopyAssignable} requirements.
5618+
56575619
\rSec3[istream.iterator.cons]{Constructors and destructor}
56585620

56595621
\indexlibrary{\idxcode{istream_iterator}!constructor}%
@@ -5665,12 +5627,16 @@
56655627
\begin{itemdescr}
56665628
\pnum
56675629
\effects
5668-
Constructs the end-of-stream iterator.
5669-
If \tcode{is_trivially_default_constructible_v<T>} is \tcode{true},
5670-
then these constructors are constexpr constructors.
5630+
Constructs the end-of-stream iterator, value-initializing \tcode{value}.
56715631

56725632
\pnum
5673-
\ensures \tcode{in_stream == nullptr}.
5633+
\ensures \tcode{in_stream == nullptr} is \tcode{true}.
5634+
5635+
\pnum
5636+
\remarks
5637+
If the initializer \tcode{T()} in the declaration \tcode{auto x = T();}
5638+
is a constant initializer\iref{expr.const},
5639+
then these constructors are \tcode{constexpr} constructors.
56745640
\end{itemdescr}
56755641

56765642

@@ -5682,12 +5648,9 @@
56825648
\begin{itemdescr}
56835649
\pnum
56845650
\effects
5685-
Initializes \tcode{in_stream} with \tcode{addressof(s)}.
5686-
\tcode{value} may be initialized during
5687-
construction or the first time it is referenced.
5688-
5689-
\pnum
5690-
\ensures \tcode{in_stream == addressof(s)}.
5651+
Initializes \tcode{in_stream} with \tcode{addressof(s)},
5652+
value-initializes \tcode{value},
5653+
and then calls \tcode{operator++()}.
56915654
\end{itemdescr}
56925655

56935656

@@ -5700,11 +5663,14 @@
57005663
\pnum
57015664
\effects
57025665
Constructs a copy of \tcode{x}.
5703-
If \tcode{is_trivially_copy_constructible_v<T>} is \tcode{true},
5704-
then this constructor is a trivial copy constructor.
57055666

57065667
\pnum
5707-
\ensures \tcode{in_stream == x.in_stream}.
5668+
\ensures \tcode{in_stream == x.in_stream} is \tcode{true}.
5669+
5670+
\pnum
5671+
\remarks
5672+
If \tcode{is_trivially_copy_constructible_v<T>} is \tcode{true},
5673+
then this constructor is trivial.
57085674
\end{itemdescr}
57095675

57105676
\indexlibrary{\idxcode{istream_iterator}!destructor}%
@@ -5714,8 +5680,7 @@
57145680

57155681
\begin{itemdescr}
57165682
\pnum
5717-
\effects
5718-
The iterator is destroyed.
5683+
\remarks
57195684
If \tcode{is_trivially_destructible_v<T>} is \tcode{true},
57205685
then this destructor is trivial.
57215686
\end{itemdescr}
@@ -5728,6 +5693,10 @@
57285693
\end{itemdecl}
57295694

57305695
\begin{itemdescr}
5696+
\pnum
5697+
\expects
5698+
\tcode{in_stream != nullptr} is \tcode{true}.
5699+
57315700
\pnum
57325701
\returns
57335702
\tcode{value}.
@@ -5739,9 +5708,13 @@
57395708
\end{itemdecl}
57405709

57415710
\begin{itemdescr}
5711+
\pnum
5712+
\expects
5713+
\tcode{in_stream != nullptr} is \tcode{true}.
5714+
57425715
\pnum
57435716
\returns
5744-
\tcode{addressof(operator*())}.
5717+
\tcode{addressof(value)}.
57455718
\end{itemdescr}
57465719

57475720
\indexlibrarymember{operator++}{istream_iterator}%
@@ -5751,11 +5724,15 @@
57515724

57525725
\begin{itemdescr}
57535726
\pnum
5754-
\requires \tcode{in_stream != nullptr}.
5727+
\expects
5728+
\tcode{in_stream != nullptr} is \tcode{true}.
57555729

57565730
\pnum
5757-
\effects
5758-
As if by: \tcode{*in_stream >> value;}
5731+
\effects Equivalent to:
5732+
\begin{codeblock}
5733+
if (!(*in_stream >> value))
5734+
in_stream = nullptr;
5735+
\end{codeblock}
57595736

57605737
\pnum
57615738
\returns
@@ -5769,14 +5746,10 @@
57695746

57705747
\begin{itemdescr}
57715748
\pnum
5772-
\requires \tcode{in_stream != nullptr}.
5773-
5774-
\pnum
5775-
\effects
5776-
As if by:
5749+
\effects Equivalent to:
57775750
\begin{codeblock}
57785751
istream_iterator tmp = *this;
5779-
*in_stream >> value;
5752+
++*this;
57805753
return tmp;
57815754
\end{codeblock}
57825755
\end{itemdescr}

0 commit comments

Comments
 (0)