Skip to content

Commit

Permalink
P0738R2 istream_iterator Cleanup (#246)
Browse files Browse the repository at this point in the history
This change is unconditional.

Resolves #35.
  • Loading branch information
miscco authored and StephanTLavavej committed Nov 7, 2019
1 parent 5add729 commit f9b1dcc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions stl/inc/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,23 @@ public:
using traits_type = _Traits;
using istream_type = basic_istream<_Elem, _Traits>;

constexpr istream_iterator() : _Myistr(nullptr), _Myval() {}
static_assert(conjunction_v<is_default_constructible<_Ty>, is_copy_constructible<_Ty>, is_copy_assignable<_Ty>>,
"istream_iterator<T> requires T to be default constructible, copy constructible, and copy assignable. "
"(N4835 [istream.iterator]/2)");

constexpr istream_iterator() {}

istream_iterator(istream_type& _Istr) : _Myistr(_STD addressof(_Istr)) {
_Getval();
}

_NODISCARD const _Ty& operator*() const {
_STL_ASSERT(_Myistr, "The stored stream pointer in_stream must be non-null");
return _Myval;
}

_NODISCARD const _Ty* operator->() const {
_STL_ASSERT(_Myistr, "The stored stream pointer in_stream must be non-null");
return _STD addressof(_Myval);
}

Expand All @@ -162,15 +168,16 @@ public:
return _Myistr == _Right._Myistr;
}

protected:
private:
void _Getval() { // get a _Ty value if possible
if (_Myistr && !(*_Myistr >> _Myval)) {
_STL_ASSERT(_Myistr, "The stored stream pointer in_stream must be non-null");
if (!(*_Myistr >> _Myval)) {
_Myistr = nullptr;
}
}

istream_type* _Myistr; // pointer to input stream
_Ty _Myval; // lookahead value (valid if _Myistr is not null)
istream_type* _Myistr{nullptr}; // pointer to input stream
_Ty _Myval{}; // lookahead value (valid if _Myistr is not null)
};

template <class _Ty, class _Elem, class _Traits, class _Diff>
Expand Down
1 change: 1 addition & 0 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
// P0548R1 Tweaking common_type And duration
// P0558R1 Resolving atomic<T> Named Base Class Inconsistencies
// P0599R1 noexcept hash
// P0738R2 istream_iterator Cleanup
// P0771R1 noexcept For std::function's Move Constructor
// P0777R1 Avoiding Unnecessary decay
// P0809R0 Comparing Unordered Containers
Expand Down

0 comments on commit f9b1dcc

Please sign in to comment.