Add support for initializer_list to wx dynamic arrays

While these array classes are deprecated in the user code, they're still
used, for compatibility, in many places in wxWidgets API and allowing to
create them from initializer_list makes using it more ergonomic as it's
now possible to just pass an initializer list of items to fill the
control with, for example, instead of appending them one by one.

Closes #23309.
This commit is contained in:
Lotendan 2023-03-02 21:34:49 +01:00 committed by Vadim Zeitlin
parent 38b2bc455c
commit 4d62df488b
5 changed files with 45 additions and 0 deletions

View file

@ -16,6 +16,7 @@
#include "wx/dynarray.h"
#include <vector>
#include <initializer_list>
// 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
@ -81,6 +82,8 @@ public:
wxArrayString(size_t sz, const char** a);
wxArrayString(size_t sz, const wchar_t** a);
wxArrayString(size_t sz, const wxString* a);
template<typename U>
wxArrayString(std::initializer_list<U> list) : wxArrayStringBase(list) { }
int Index(const wxString& str, bool bCase = true, bool bFromEnd = false) const;
@ -182,6 +185,9 @@ public:
wxArrayString(size_t sz, const wxString* a);
// copy ctor
wxArrayString(const wxArrayString& array);
// list constructor
template<typename U>
wxArrayString(std::initializer_list<U> list) { Init(false); assign(list.begin(), list.end()); }
// assignment operator
wxArrayString& operator=(const wxArrayString& src);
// not virtual, this class should not be derived from