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

<deque>: Use _Next_iter and _Prev_iter #1161

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions stl/inc/deque
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,10 @@ public:

if (_Off <= _Mysize() / 2) { // closer to front, push to front then rotate
emplace_front(_STD forward<_Valty>(_Val)...);
_STD rotate(begin(), begin() + 1, begin() + static_cast<difference_type>(1 + _Off));
_STD rotate(begin(), _Next_iter(begin()), begin() + static_cast<difference_type>(1 + _Off));
} else { // closer to back, push to back then rotate
emplace_back(_STD forward<_Valty>(_Val)...);
_STD rotate(begin() + static_cast<difference_type>(_Off), end() - 1, end());
_STD rotate(begin() + static_cast<difference_type>(_Off), _Prev_iter(end()), end());
}
return begin() + static_cast<difference_type>(_Off);
}
Expand Down Expand Up @@ -1064,15 +1064,15 @@ public:
_STL_VERIFY(!empty(), "back() called on empty deque");
#endif // _CONTAINER_DEBUG_LEVEL > 0

return *(_Unchecked_end() - 1);
return *(_Prev_iter(_Unchecked_end()));
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
}

_NODISCARD const_reference back() const noexcept /* strengthened */ {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(!empty(), "back() called on empty deque");
#endif // _CONTAINER_DEBUG_LEVEL > 0

return *(_Unchecked_end() - 1);
return *(_Prev_iter(_Unchecked_end()));
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
}

void push_front(const _Ty& _Val) {
Expand Down Expand Up @@ -1197,10 +1197,10 @@ public:

if (_Off <= _Mysize() / 2) { // closer to front, push to front then copy
push_front(_Val);
_STD rotate(begin(), begin() + 1, begin() + static_cast<difference_type>(1 + _Off));
_STD rotate(begin(), _Next_iter(begin()), begin() + static_cast<difference_type>(1 + _Off));
} else { // closer to back, push to back then copy
push_back(_Val);
_STD rotate(begin() + static_cast<difference_type>(_Off), end() - 1, end());
_STD rotate(begin() + static_cast<difference_type>(_Off), _Prev_iter(end()), end());
}

return begin() + static_cast<difference_type>(_Off);
Expand Down
19 changes: 18 additions & 1 deletion tests/std/tests/Dev10_500860_overloaded_address_of/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ constexpr bool can_addressof = false;
template <typename T>
constexpr bool can_addressof<T, void_t<decltype(addressof(declval<T>()))>> = true;

void test_LWG_2598() {
void test_LWG_2598() { // COMPILE-ONLY
STATIC_ASSERT(can_addressof<int&>);
STATIC_ASSERT(can_addressof<const int&>);
STATIC_ASSERT(can_addressof<volatile int&>);
Expand All @@ -292,3 +292,20 @@ void test_LWG_2598() {
STATIC_ASSERT(!can_addressof<volatile int>);
STATIC_ASSERT(!can_addressof<const volatile int>);
}

// Also test DevCom-1134328, in which `deque<S*>::_Unchecked_iterator{} - 1` finds
// operator-(const S&, int) by argument-dependent lookup causing overload resolution
// to fail due to ambiguity when compiling 64-bit.
struct S {
S() = default;

template <typename T>
S(T&&);
};

S operator-(const S&, int);

void test_DevCom_1134328() { // COMPILE-ONLY
deque<S*> d{nullptr};
(void) d.back();
}