From 28342d7882ef0ccd1dc447463b45f7571ddbcf66 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 4 Jan 2019 23:31:12 +0100 Subject: [PATCH] Fix building with wxUSE_STD_CONTAINERS=1 in C++17 mode Don't use std::bind2nd() which doesn't exist in C++17 any longer. Replace it with a lambda when using C++11 which is simpler and more clear and also replace the use of functors in std::sort() calls with lambdas. Closes #18319. --- src/common/arrstr.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/common/arrstr.cpp b/src/common/arrstr.cpp index 721a63f50b..e78f8259b5 100644 --- a/src/common/arrstr.cpp +++ b/src/common/arrstr.cpp @@ -59,6 +59,24 @@ wxArrayString::wxArrayString(size_t sz, const wxString* a) #include "wx/arrstr.h" +#if __cplusplus >= 201103L + +int wxArrayString::Index(const wxString& str, bool bCase, bool WXUNUSED(bFromEnd)) const +{ + int n = 0; + for ( const auto& s: *this ) + { + if ( s.IsSameAs(str, bCase) ) + return n; + + ++n; + } + + return wxNOT_FOUND; +} + +#else // C++98 version + #include "wx/beforestd.h" #include #include "wx/afterstd.h" @@ -130,9 +148,20 @@ wxStringCompareLess wxStringCompare(F f) return wxStringCompareLess(f); } +#endif // C++11/C++98 + void wxArrayString::Sort(CompareFunction function) { - std::sort(begin(), end(), wxStringCompare(function)); + std::sort(begin(), end(), +#if __cplusplus >= 201103L + [function](const wxString& s1, const wxString& s2) + { + return function(s1, s2) < 0; + } +#else // C++98 version + wxStringCompare(function) +#endif // C++11/C++98 + ); } void wxArrayString::Sort(bool reverseOrder) @@ -155,7 +184,16 @@ int wxSortedArrayString::Index(const wxString& str, "search parameters ignored for sorted array" ); wxSortedArrayString::const_iterator - it = std::lower_bound(begin(), end(), str, wxStringCompare(wxStringCmp())); + it = std::lower_bound(begin(), end(), str, +#if __cplusplus >= 201103L + [](const wxString& s1, const wxString& s2) + { + return s1 < s2; + } +#else // C++98 version + wxStringCompare(wxStringCmp()) +#endif // C++11/C++98 + ); if ( it == end() || str.Cmp(*it) != 0 ) return wxNOT_FOUND;