diff --git a/configure b/configure index 75bca8e631..6780697b98 100755 --- a/configure +++ b/configure @@ -1125,6 +1125,7 @@ enable_mem_tracing enable_shared enable_stl enable_std_containers +enable_std_containers_compat enable_std_iostreams enable_std_string enable_std_string_conv_in_wxstring @@ -2055,6 +2056,7 @@ Optional Features: --disable-shared create static library instead of shared --enable-stl use standard C++ classes for everything --enable-std_containers use standard C++ container classes + --enable-std_containers_compat use standard C++ container classes when it can be done compatible --enable-std_iostreams use standard C++ stream classes --enable-std_string use standard C++ string classes --enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString @@ -4076,6 +4078,7 @@ esac DEFAULT_wxUSE_ALL_FEATURES=yes DEFAULT_wxUSE_STD_CONTAINERS=no +DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY=$DEFAULT_STD_FLAG DEFAULT_wxUSE_STD_IOSTREAM=$DEFAULT_STD_FLAG DEFAULT_wxUSE_STD_STRING=$DEFAULT_STD_FLAG @@ -6018,6 +6021,7 @@ $as_echo "$result" >&6; } if test "$wxUSE_STL" = "yes"; then DEFAULT_wxUSE_STD_CONTAINERS=yes + DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY=yes DEFAULT_wxUSE_STD_IOSTREAM=yes DEFAULT_wxUSE_STD_STRING=yes fi @@ -6066,6 +6070,50 @@ fi $as_echo "$result" >&6; } + enablestring= + defaultval= + if test -z "$defaultval"; then + if test x"$enablestring" = xdisable; then + defaultval=yes + else + defaultval=no + fi + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --${enablestring:-enable}-std_containers_compat" >&5 +$as_echo_n "checking for --${enablestring:-enable}-std_containers_compat... " >&6; } + # Check whether --enable-std_containers_compat was given. +if test "${enable_std_containers_compat+set}" = set; then : + enableval=$enable_std_containers_compat; + if test "$enableval" = yes; then + wx_cv_use_std_containers_compat='wxUSE_STD_CONTAINERS_COMPATIBLY=yes' + else + wx_cv_use_std_containers_compat='wxUSE_STD_CONTAINERS_COMPATIBLY=no' + fi + +else + + wx_cv_use_std_containers_compat='wxUSE_STD_CONTAINERS_COMPATIBLY=${'DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY":-$defaultval}" + +fi + + + eval "$wx_cv_use_std_containers_compat" + + if test x"$enablestring" = xdisable; then + if test $wxUSE_STD_CONTAINERS_COMPATIBLY = no; then + result=yes + else + result=no + fi + else + result=$wxUSE_STD_CONTAINERS_COMPATIBLY + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $result" >&5 +$as_echo "$result" >&6; } + + enablestring= defaultval= if test -z "$defaultval"; then @@ -34499,6 +34547,11 @@ if test "$wxUSE_STD_CONTAINERS" = "yes"; then fi +if test "$wxUSE_STD_CONTAINERS_COMPATIBLY" = "yes"; then + $as_echo "#define wxUSE_STD_CONTAINERS_COMPATIBLY 1" >>confdefs.h + +fi + if test "$wxUSE_STD_IOSTREAM" = "yes"; then $as_echo "#define wxUSE_STD_IOSTREAM 1" >>confdefs.h diff --git a/configure.in b/configure.in index dcb099087d..1a061bce62 100644 --- a/configure.in +++ b/configure.in @@ -331,6 +331,7 @@ dnl default) DEFAULT_wxUSE_ALL_FEATURES=yes DEFAULT_wxUSE_STD_CONTAINERS=no +DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY=$DEFAULT_STD_FLAG DEFAULT_wxUSE_STD_IOSTREAM=$DEFAULT_STD_FLAG DEFAULT_wxUSE_STD_STRING=$DEFAULT_STD_FLAG @@ -646,10 +647,12 @@ WX_ARG_DISABLE(shared, [ --disable-shared create static library inst WX_ARG_ENABLE(stl, [ --enable-stl use standard C++ classes for everything], wxUSE_STL) if test "$wxUSE_STL" = "yes"; then DEFAULT_wxUSE_STD_CONTAINERS=yes + DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY=yes DEFAULT_wxUSE_STD_IOSTREAM=yes DEFAULT_wxUSE_STD_STRING=yes fi WX_ARG_ENABLE(std_containers,[ --enable-std_containers use standard C++ container classes], wxUSE_STD_CONTAINERS) +WX_ARG_ENABLE(std_containers_compat, [ --enable-std_containers_compat use standard C++ container classes when it can be done compatible], wxUSE_STD_CONTAINERS_COMPATIBLY) WX_ARG_ENABLE(std_iostreams, [ --enable-std_iostreams use standard C++ stream classes], wxUSE_STD_IOSTREAM) WX_ARG_ENABLE(std_string, [ --enable-std_string use standard C++ string classes], wxUSE_STD_STRING) WX_ARG_ENABLE(std_string_conv_in_wxstring, [ --enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString], wxUSE_STD_STRING_CONV_IN_WXSTRING) @@ -5654,6 +5657,10 @@ if test "$wxUSE_STD_CONTAINERS" = "yes"; then AC_DEFINE(wxUSE_STD_CONTAINERS) fi +if test "$wxUSE_STD_CONTAINERS_COMPATIBLY" = "yes"; then + AC_DEFINE(wxUSE_STD_CONTAINERS_COMPATIBLY) +fi + if test "$wxUSE_STD_IOSTREAM" = "yes"; then AC_DEFINE(wxUSE_STD_IOSTREAM) fi diff --git a/docs/changes.txt b/docs/changes.txt index 5cc7000284..7269c040ad 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -32,6 +32,7 @@ Changes in behaviour which may result in build errors All: +- Allow calling wxItemContainer::Add() and similar with std::vector<> argument. - Add "%z" support to printf()-like functions like wxString::Format() (RIVDSL). - Add wxPowerResourceBlocker (Tobias Taschner). - Add wxApp::StoreCurrentException() and RethrowStoredException() and implement diff --git a/include/wx/android/setup.h b/include/wx/android/setup.h index 6033a9d3ee..d1a53cc228 100644 --- a/include/wx/android/setup.h +++ b/include/wx/android/setup.h @@ -299,12 +299,25 @@ #define wxUSE_STL 0 // This is not a real option but is used as the default value for -// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS. +// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY. // // Set it to 0 if you want to disable the use of all standard classes // completely for some reason. #define wxUSE_STD_DEFAULT 1 +// Use standard C++ containers where it can be done without breaking backwards +// compatibility. +// +// This provides better interoperability with the standard library, e.g. with +// this option on it's possible to insert std::vector<> into many wxWidgets +// containers directly. +// +// Default is 1. +// +// Recommended setting is 1 unless you want to avoid all dependencies on the +// standard library. +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + // Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<> // and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but // usually more limited) implementations are used which allows to avoid the diff --git a/include/wx/arrstr.h b/include/wx/arrstr.h index d76a2859b4..9d5e1ef4ab 100644 --- a/include/wx/arrstr.h +++ b/include/wx/arrstr.h @@ -14,6 +14,10 @@ #include "wx/defs.h" #include "wx/string.h" +#if wxUSE_STD_CONTAINERS_COMPATIBLY + #include +#endif + // these functions are only used in STL build now but we define them in any // case for compatibility with the existing code outside of the library which // could be using them @@ -474,6 +478,16 @@ public: m_data.ptr = strings; } +#if wxUSE_STD_CONTAINERS_COMPATIBLY + // construct an adapter from a vector of strings (of any type) + template + wxArrayStringsAdapter(const std::vector& strings) + : m_type(wxSTRING_POINTER), m_size(strings.size()) + { + m_data.ptr = &strings[0]; + } +#endif // wxUSE_STD_CONTAINERS_COMPATIBLY + // construct an adapter from a single wxString wxArrayStringsAdapter(const wxString& s) : m_type(wxSTRING_POINTER), m_size(1) diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index f022d098ac..93fc99c2a7 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -309,6 +309,14 @@ # endif #endif /* !defined(wxUSE_STD_CONTAINERS) */ +#ifndef wxUSE_STD_CONTAINERS_COMPATIBLY +# ifdef wxABORT_ON_CONFIG_ERROR +# error "wxUSE_STD_CONTAINERS_COMPATIBLY must be defined, please read comment near the top of this file." +# else +# define wxUSE_STD_CONTAINERS_COMPATIBLY 0 +# endif +#endif /* !defined(wxUSE_STD_CONTAINERS_COMPATIBLY) */ + #ifndef wxUSE_STD_STRING_CONV_IN_WXSTRING # ifdef wxABORT_ON_CONFIG_ERROR # error "wxUSE_STD_STRING_CONV_IN_WXSTRING must be defined, please read comment near the top of this file." diff --git a/include/wx/ctrlsub.h b/include/wx/ctrlsub.h index c5a82c9ae7..61912feb68 100644 --- a/include/wx/ctrlsub.h +++ b/include/wx/ctrlsub.h @@ -216,6 +216,10 @@ public: wxClientData **clientData) { return AppendItems(wxArrayStringsAdapter(n, items), clientData); } + template + int Append(const std::vector& items) + { return AppendItems(items); } + // only for RTTI needs (separate name) void AppendString(const wxString& item) { Append(item); } @@ -255,6 +259,9 @@ public: wxClientData **clientData) { return InsertItems(wxArrayStringsAdapter(n, items), pos, clientData); } + template + int Insert(const std::vector& items, unsigned int pos) + { return InsertItems(items, pos); } // replacing items // --------------- @@ -272,6 +279,10 @@ public: void Set(unsigned int n, const wxString *items, wxClientData **clientData) { Clear(); Append(n, items, clientData); } + template + void Set(const std::vector& items) + { Clear(); Append(items); } + // deleting items // -------------- diff --git a/include/wx/gtk/setup0.h b/include/wx/gtk/setup0.h index f97c5d8d13..0a768dd1f7 100644 --- a/include/wx/gtk/setup0.h +++ b/include/wx/gtk/setup0.h @@ -300,12 +300,25 @@ #define wxUSE_STL 0 // This is not a real option but is used as the default value for -// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS. +// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY. // // Set it to 0 if you want to disable the use of all standard classes // completely for some reason. #define wxUSE_STD_DEFAULT 1 +// Use standard C++ containers where it can be done without breaking backwards +// compatibility. +// +// This provides better interoperability with the standard library, e.g. with +// this option on it's possible to insert std::vector<> into many wxWidgets +// containers directly. +// +// Default is 1. +// +// Recommended setting is 1 unless you want to avoid all dependencies on the +// standard library. +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + // Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<> // and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but // usually more limited) implementations are used which allows to avoid the diff --git a/include/wx/motif/setup0.h b/include/wx/motif/setup0.h index 8d7c4095c7..bf7b39b252 100644 --- a/include/wx/motif/setup0.h +++ b/include/wx/motif/setup0.h @@ -300,12 +300,25 @@ #define wxUSE_STL 0 // This is not a real option but is used as the default value for -// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS. +// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY. // // Set it to 0 if you want to disable the use of all standard classes // completely for some reason. #define wxUSE_STD_DEFAULT 1 +// Use standard C++ containers where it can be done without breaking backwards +// compatibility. +// +// This provides better interoperability with the standard library, e.g. with +// this option on it's possible to insert std::vector<> into many wxWidgets +// containers directly. +// +// Default is 1. +// +// Recommended setting is 1 unless you want to avoid all dependencies on the +// standard library. +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + // Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<> // and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but // usually more limited) implementations are used which allows to avoid the diff --git a/include/wx/msw/setup0.h b/include/wx/msw/setup0.h index c6d6b3112e..04d041509a 100644 --- a/include/wx/msw/setup0.h +++ b/include/wx/msw/setup0.h @@ -300,12 +300,25 @@ #define wxUSE_STL 0 // This is not a real option but is used as the default value for -// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS. +// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY. // // Set it to 0 if you want to disable the use of all standard classes // completely for some reason. #define wxUSE_STD_DEFAULT 1 +// Use standard C++ containers where it can be done without breaking backwards +// compatibility. +// +// This provides better interoperability with the standard library, e.g. with +// this option on it's possible to insert std::vector<> into many wxWidgets +// containers directly. +// +// Default is 1. +// +// Recommended setting is 1 unless you want to avoid all dependencies on the +// standard library. +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + // Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<> // and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but // usually more limited) implementations are used which allows to avoid the diff --git a/include/wx/msw/wince/setup.h b/include/wx/msw/wince/setup.h index 569b23f5f8..dbd627a867 100644 --- a/include/wx/msw/wince/setup.h +++ b/include/wx/msw/wince/setup.h @@ -300,12 +300,25 @@ #define wxUSE_STL 0 // This is not a real option but is used as the default value for -// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS. +// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY. // // Set it to 0 if you want to disable the use of all standard classes // completely for some reason. #define wxUSE_STD_DEFAULT 1 +// Use standard C++ containers where it can be done without breaking backwards +// compatibility. +// +// This provides better interoperability with the standard library, e.g. with +// this option on it's possible to insert std::vector<> into many wxWidgets +// containers directly. +// +// Default is 1. +// +// Recommended setting is 1 unless you want to avoid all dependencies on the +// standard library. +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + // Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<> // and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but // usually more limited) implementations are used which allows to avoid the diff --git a/include/wx/osx/setup0.h b/include/wx/osx/setup0.h index b32448329d..7343a003c6 100644 --- a/include/wx/osx/setup0.h +++ b/include/wx/osx/setup0.h @@ -301,12 +301,25 @@ #define wxUSE_STL 0 // This is not a real option but is used as the default value for -// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS. +// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY. // // Set it to 0 if you want to disable the use of all standard classes // completely for some reason. #define wxUSE_STD_DEFAULT 1 +// Use standard C++ containers where it can be done without breaking backwards +// compatibility. +// +// This provides better interoperability with the standard library, e.g. with +// this option on it's possible to insert std::vector<> into many wxWidgets +// containers directly. +// +// Default is 1. +// +// Recommended setting is 1 unless you want to avoid all dependencies on the +// standard library. +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + // Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<> // and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but // usually more limited) implementations are used which allows to avoid the diff --git a/include/wx/setup_inc.h b/include/wx/setup_inc.h index 14b719215f..73ec69f0b6 100644 --- a/include/wx/setup_inc.h +++ b/include/wx/setup_inc.h @@ -296,12 +296,25 @@ #define wxUSE_STL 0 // This is not a real option but is used as the default value for -// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS. +// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY. // // Set it to 0 if you want to disable the use of all standard classes // completely for some reason. #define wxUSE_STD_DEFAULT 1 +// Use standard C++ containers where it can be done without breaking backwards +// compatibility. +// +// This provides better interoperability with the standard library, e.g. with +// this option on it's possible to insert std::vector<> into many wxWidgets +// containers directly. +// +// Default is 1. +// +// Recommended setting is 1 unless you want to avoid all dependencies on the +// standard library. +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + // Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<> // and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but // usually more limited) implementations are used which allows to avoid the diff --git a/include/wx/univ/setup0.h b/include/wx/univ/setup0.h index fe56759b67..421ddfb1a3 100644 --- a/include/wx/univ/setup0.h +++ b/include/wx/univ/setup0.h @@ -299,12 +299,25 @@ #define wxUSE_STL 0 // This is not a real option but is used as the default value for -// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS. +// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY. // // Set it to 0 if you want to disable the use of all standard classes // completely for some reason. #define wxUSE_STD_DEFAULT 1 +// Use standard C++ containers where it can be done without breaking backwards +// compatibility. +// +// This provides better interoperability with the standard library, e.g. with +// this option on it's possible to insert std::vector<> into many wxWidgets +// containers directly. +// +// Default is 1. +// +// Recommended setting is 1 unless you want to avoid all dependencies on the +// standard library. +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + // Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<> // and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but // usually more limited) implementations are used which allows to avoid the diff --git a/interface/wx/ctrlsub.h b/interface/wx/ctrlsub.h index 728cba07d5..00b718ad8a 100644 --- a/interface/wx/ctrlsub.h +++ b/interface/wx/ctrlsub.h @@ -253,6 +253,21 @@ public: */ int Append(const wxArrayString& items); + /** + Appends several items at once into the control. + + This is the same as the overload taking wxArrayString, except that it + works with the standard vector container. + + The template argument @c T can be any type convertible to wxString, + including wxString itself but also @c std::string, @c char* or @c + wchar_t*. + + @since 3.1.0 + */ + template + int Append(const std::vector& items); + /** Appends several items at once into the control. @@ -520,6 +535,21 @@ public: */ int Insert(const wxArrayString& items, unsigned int pos); + /** + Inserts several items at once into the control. + + This is the same as the overload taking wxArrayString, except that it + works with the standard vector container. + + The template argument @c T can be any type convertible to wxString, + including wxString itself but also @c std::string, @c char* or @c + wchar_t*. + + @since 3.1.0 + */ + template + int Insert(const std::vector& items); + /** Inserts several items at once into the control. @@ -633,6 +663,21 @@ public: */ void Set(const wxArrayString& items); + /** + Replaces the current control contents with the given items. + + This is the same as the overload taking wxArrayString, except that it + works with the standard vector container. + + The template argument @c T can be any type convertible to wxString, + including wxString itself but also @c std::string, @c char* or @c + wchar_t*. + + @since 3.1.0 + */ + template + void Set(const std::vector& items); + /** Replaces the current control contents with the given items. diff --git a/setup.h.in b/setup.h.in index 2dd14ffb0e..6de5c1dadb 100644 --- a/setup.h.in +++ b/setup.h.in @@ -209,6 +209,8 @@ #define wxUSE_STD_DEFAULT 0 +#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT + #define wxUSE_STD_CONTAINERS 0 #define wxUSE_STD_IOSTREAM wxUSE_STD_DEFAULT