Fix using std::reverse() with wxString iterators in a proper way
The solution with specializing std::iter_swap() for wxString::iterator was not conforming as the iterator was still not swappable, as it is required to be. Fix this by providing std::swap() overload for wxString::iterator, which is correct and even simpler. This allows std::reverse(s.begin(), s.end()) work with clang too and incidentally avoids warnings about the code relying on non-conforming extensions with MSVS 2017 which were due to the fact that iter_swap() workaround wasn't enabled for it, while the new swap() overload is.
This commit is contained in:
@@ -360,6 +360,23 @@ void swap<wxUniCharRef>(wxUniCharRef& lhs, wxUniCharRef& rhs)
|
||||
|
||||
} // namespace std
|
||||
|
||||
#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(10)
|
||||
|
||||
// For std::iter_swap() to work with wxString::iterator, which uses
|
||||
// wxUniCharRef as its reference type, we need to ensure that swap() works with
|
||||
// wxUniCharRef objects by defining this overload.
|
||||
//
|
||||
// See https://bugs.llvm.org/show_bug.cgi?id=28559#c9
|
||||
inline
|
||||
void swap(wxUniCharRef&& lhs, wxUniCharRef&& rhs)
|
||||
{
|
||||
wxUniChar tmp = lhs;
|
||||
lhs = rhs;
|
||||
rhs = tmp;
|
||||
}
|
||||
|
||||
#endif // C++11
|
||||
|
||||
|
||||
// Comparison operators for the case when wxUniChar(Ref) is the second operand
|
||||
// implemented in terms of member comparison functions
|
||||
|
Reference in New Issue
Block a user