diff --git a/include/wx/string.h b/include/wx/string.h index 7b63c81e2a..e6f6931300 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -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 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 // --------------------------------------------------------------------------- diff --git a/include/wx/unichar.h b/include/wx/unichar.h index 01c188907e..a0cc71937b 100644 --- a/include/wx/unichar.h +++ b/include/wx/unichar.h @@ -360,6 +360,23 @@ void swap(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 diff --git a/tests/strings/stdstrings.cpp b/tests/strings/stdstrings.cpp index e9682b5761..71cafa3632 100644 --- a/tests/strings/stdstrings.cpp +++ b/tests/strings/stdstrings.cpp @@ -626,13 +626,7 @@ void StdStringTestCase::StdConversion() void StdStringTestCase::StdAlgo() { - // Unfortunately this currently doesn't work with libc++ in C++11 mode, see - // comment near iter_swap() definition in wx/string.h. -#if __cplusplus < 201103L || !defined(_LIBCPP_VERSION) wxString s("AB"); std::reverse(s.begin(), s.end()); CPPUNIT_ASSERT_EQUAL( "BA", s ); -#else - wxLogWarning("Skipping std::reverse() test broken with C++11/libc++"); -#endif }