From cf2bb21885a8ccf76940e9b5fda158f292b66f64 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 11 Apr 2021 13:24:33 +0200 Subject: [PATCH] Add a note about using ranged-based for loop with wxString It is surprising that "for (auto& c: s)" doesn't compile, so document this and propose a replacement. Do not document the fact that "for (auto c: s)" actually allows to modify the string via "c" (which is still wxUniCharRef) as this is probably just going to confuse people more than help. --- docs/doxygen/overviews/unicode.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/doxygen/overviews/unicode.h b/docs/doxygen/overviews/unicode.h index 6712e5476c..5b323204d2 100644 --- a/docs/doxygen/overviews/unicode.h +++ b/docs/doxygen/overviews/unicode.h @@ -255,6 +255,11 @@ n: string iterators instead if possible or replace this expression with @code s.c_str() + n @endcode otherwise. + - When using C++11 range-based for loop, the natural construct for iterating + over wxString @code for ( auto& ch: s ) @endcode doesn't compile because of + the unusual iterator type and @code for ( wxUniCharRef ch: s ) @endcode + needs to be used instead. + Another class of problems is related to the fact that the value returned by @c c_str() itself is also not just a pointer to a buffer but a value of helper class wxCStrData which is implicitly convertible to both narrow and wide