Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement P2325R3 Views Should Not Be Required To Be Default Constructible #2012

Merged
merged 9 commits into from
Jun 29, 2021
91 changes: 48 additions & 43 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,18 @@ namespace ranges {
}

_Copyable_box& operator=(const _Copyable_box& _That) noexcept(is_nothrow_copy_constructible_v<_Ty>) {
if (_STD addressof(_That) != this) {
if (_Engaged) {
_Val.~_Ty();
_Engaged = false;
}
if (_STD addressof(_That) == this) {
return *this;
}

if (_That._Engaged) {
_Construct_in_place(_Val, _That._Val);
_Engaged = true;
}
if (_Engaged) {
_Val.~_Ty();
_Engaged = false;
}

if (_That._Engaged) {
_Construct_in_place(_Val, _That._Val);
_Engaged = true;
}

return *this;
Expand Down Expand Up @@ -345,16 +347,18 @@ namespace ranges {
}

_Copyable_box& operator=(_Copyable_box&& _That) noexcept(is_nothrow_move_constructible_v<_Ty>) {
if (_STD addressof(_That) != this) {
if (_Engaged) {
_Val.~_Ty();
_Engaged = false;
}
if (_STD addressof(_That) == this) {
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
return *this;
}

if (_That._Engaged) {
_Construct_in_place(_Val, _STD move(_That._Val));
_Engaged = true;
}
if (_Engaged) {
_Val.~_Ty();
_Engaged = false;
}

if (_That._Engaged) {
_Construct_in_place(_Val, _STD move(_That._Val));
_Engaged = true;
}

return *this;
Expand Down Expand Up @@ -2506,6 +2510,31 @@ namespace ranges {
/* [[no_unique_address]] */ _Vw _Range{};
range_difference_t<_Vw> _Count = 0;

_NODISCARD constexpr auto _Find_first() {
if constexpr (!sized_range<_Vw>) {
return _RANGES next(_RANGES begin(_Range), _Count, _RANGES end(_Range));
}
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved

auto _Offset = _RANGES distance(_Range);
if constexpr (bidirectional_range<_Vw> && common_range<_Vw>) {
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
if (_Count >= _Offset / 2) {
auto _Result = _RANGES end(_Range);
while (_Offset > _Count) {
--_Offset;
--_Result;
}

return _Result;
}
}

if (_Offset > _Count) {
_Offset = _Count;
}

return _RANGES next(_RANGES begin(_Range), _Offset);
}

public:
drop_view() requires default_initializable<_Vw> = default;

Expand Down Expand Up @@ -2539,31 +2568,7 @@ namespace ranges {
}
}

same_as<iterator_t<_Vw>> auto _Result = [this] {
if constexpr (!sized_range<_Vw>) {
return _RANGES next(_RANGES begin(_Range), _Count, _RANGES end(_Range));
}

auto _Offset = _RANGES distance(_Range);
if constexpr (bidirectional_range<_Vw> && common_range<_Vw>) {
if (_Count >= _Offset / 2) {
auto _Result = _RANGES end(_Range);
while (_Offset > _Count) {
--_Offset;
--_Result;
}

return _Result;
}
}

if (_Offset > _Count) {
_Offset = _Count;
}

return _RANGES next(_RANGES begin(_Range), _Offset);
}();

same_as<iterator_t<_Vw>> auto _Result = _Find_first();
if constexpr (forward_range<_Vw>) {
this->_Set_cache(_Range, _Result);
}
Expand Down