diff --git a/CHANGES.current b/CHANGES.current index 1ec7a6435..7e7232383 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,23 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-07-30: wsfulton + C++20 has deprecated std::basic_string<>::reserve() and the C++11 method + std::basic_string<>::shrink_to_fit() is a replacement that can be used. + std_string.i and std_wstring.i provided wrappers for reserve with the following + template instantiations: + + %template(string) std::basic_string; + %template(wstring) std::basic_string; + + The reserve method is no longer wrapped, however the shrink_to_fit() method + can be used as an alternative from the target language (the generated wrappers + call reserve() instead if C++<=20). + + Note that std::basic_string<>::reserve(size_t n) is still wrapped unchanged. + + *** POTENTIAL INCOMPATIBILITY *** + 2022-07-30: wsfulton [Tcl] Add support for std::unique_ptr in std_unique_ptr.i. Add support for std::auto_ptr in std_auto_ptr.i. diff --git a/Examples/test-suite/python/li_std_string_extra_runme.py b/Examples/test-suite/python/li_std_string_extra_runme.py index 96c64163d..71620e7fb 100644 --- a/Examples/test-suite/python/li_std_string_extra_runme.py +++ b/Examples/test-suite/python/li_std_string_extra_runme.py @@ -15,6 +15,11 @@ if li_std_string_extra.test_value(x) != x: if li_std_string_extra.test_const_reference(x) != x: raise RuntimeError("bad string mapping") +s = li_std_string_extra.string("1234567890") +size = s.size() +if size != 10: + raise "Incorrect size" +s.shrink_to_fit() s = li_std_string_extra.string("he") #s += "ll" diff --git a/Lib/std/std_basic_string.i b/Lib/std/std_basic_string.i index fb7afc1e6..e95cb4765 100644 --- a/Lib/std/std_basic_string.i +++ b/Lib/std/std_basic_string.i @@ -55,7 +55,16 @@ namespace std { size_type capacity() const; - void reserve(size_type __res_arg = 0); + void reserve(size_type __res_arg); + %extend { + void shrink_to_fit() { + %#if __cplusplus >= 202002L + self->shrink_to_fit(); + %#else + self->reserve(); + %#endif + } + } // Modifiers: