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:
@@ -3980,32 +3980,6 @@ namespace std
|
||||
|
||||
#endif // C++11
|
||||
|
||||
// Specialize std::iter_swap in C++11 to make std::reverse() work with wxString
|
||||
// iterators: unlike in C++98, where iter_swap() is required to deal with the
|
||||
// iterator::reference being different from "iterator::value_type&", in C++11
|
||||
// iter_swap() just calls swap() by default and this doesn't work for us as
|
||||
// wxUniCharRef is not the same as "wxUniChar&".
|
||||
//
|
||||
// Unfortunately currently iter_swap() can't be specialized when using libc++,
|
||||
// see https://llvm.org/bugs/show_bug.cgi?id=28559
|
||||
#if (__cplusplus >= 201103L) && !defined(_LIBCPP_VERSION)
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
inline void
|
||||
iter_swap<wxString::iterator>(wxString::iterator i1, wxString::iterator i2)
|
||||
{
|
||||
// We don't check for i1 == i2, this won't happen in normal use, so
|
||||
// don't pessimize the common code to account for it.
|
||||
wxUniChar tmp = *i1;
|
||||
*i1 = *i2;
|
||||
*i2 = tmp;
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
#endif // C++11
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Implementation only from here until the end of file
|
||||
// ---------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user