wxArray usage! Topic is solved
wxArray usage!
Hello,
Could anyone tell me how to declare and use a wxArray of a struct:
I thought wxArray is a template, just use "wxArray<My struct type>", but it is not.
and BTW: What is the diference between a wxList and a wxArray.
Thank you for your undestanding.
Could anyone tell me how to declare and use a wxArray of a struct:
I thought wxArray is a template, just use "wxArray<My struct type>", but it is not.
and BTW: What is the diference between a wxList and a wxArray.
Thank you for your undestanding.
Re: wxArray usage!
You would need the macros described in the documentation to declare a new array type first:tomay3000 wrote:Could anyone tell me how to declare and use a wxArray of a struct:
I thought wxArray is a template, just use "wxArray<My struct type>", but it is not.
http://docs.wxwidgets.org/trunk/classwx ... _01_4.html
However, it's discouraged to use these classes nowadays, use std containers instead, e.g. std::vector.
They can do almost the same things, but because of differences internally, they perform differently for different tasks.tomay3000 wrote:and BTW: What is the difference between a wxList and a wxArray.
In an array all elements lie after each other in memory, so random access (array[17]) is fast. But if you want to add or remove an item in the middle, lots of data needs to get moved around and therefore it's slow.
A list is usually implemented as a "linked" list where each element has pointers to the previous and next element. This means that adding or removing elements in the middle of the list is fast, because you only need to change some pointers. But random access is slow, because to find the element with a specific index, you need to iterate over the elements until you reach the correct one.
Use the source, Luke!
Re: wxArray usage!
Shame on me,
even thought I have read the documentation of both wxArray and wxList, and because I have never used them in wxWidgets before, I forget I studied Lists implementation in the university a long time ago
it is very unfortunate that these container types usage is discouraged compared to the standard C++ STL ones
Thank you for the help.
even thought I have read the documentation of both wxArray and wxList, and because I have never used them in wxWidgets before, I forget I studied Lists implementation in the university a long time ago
it is very unfortunate that these container types usage is discouraged compared to the standard C++ STL ones
Thank you for the help.
Re: wxArray usage!
Hi,
Why do you say it is unfortunate?
STL is part of the standard now and wx containers are not.
In a recent wx version they are just a wrappers around the STL ones. So it will be much easier to just use STL directly.
Granted some API is unavoidable, but most of the time you should work with STL containers.
Thank you.
Why do you say it is unfortunate?
STL is part of the standard now and wx containers are not.
In a recent wx version they are just a wrappers around the STL ones. So it will be much easier to just use STL directly.
Granted some API is unavoidable, but most of the time you should work with STL containers.
Thank you.
Re: wxArray usage!
Because every new wxWidgets learner has to know its containers, and they are going to be replaced by the C++ standard ones in the future and wxUSE_STL and wxUSE_STD_CONTAINERS are not set by default.
and what will happen to wxArrayString e.g in the future!
and what will happen to wxArrayString e.g in the future!
Re: wxArray usage!
Hi,
No, they don't.
wxWidgets is a C++ library and if you don't know STL, you need to start with the C++.
And I would guess that it will be replaced with std::vector<wxString>.
Also, those container classes were created for very old C++ compilers that didn't support containers/STL. They are currently an ancient history, but because there are code out there that depends on them to be exist, wx developers can't deprecate them.
Thank you.
No, they don't.
wxWidgets is a C++ library and if you don't know STL, you need to start with the C++.
And I would guess that it will be replaced with std::vector<wxString>.
Also, those container classes were created for very old C++ compilers that didn't support containers/STL. They are currently an ancient history, but because there are code out there that depends on them to be exist, wx developers can't deprecate them.
Thank you.
Re: wxArray usage!
FWIW, you can still use the wx containers and i don't think they'll be gone anytime soon.
Use the source, Luke!
Re: wxArray usage!
Thank you guys for the help.
After a long reading I have decided to use wxVector template over wxArray macros. I have seen "Vadim Zeitlin" getting rid of wxArray implementation in the Github repo and replacing it with its wxVector equivalents.
take a look here: https://github.com/wxWidgets/wxWidgets/ ... 28ad6186ed
After a long reading I have decided to use wxVector template over wxArray macros. I have seen "Vadim Zeitlin" getting rid of wxArray implementation in the Github repo and replacing it with its wxVector equivalents.
take a look here: https://github.com/wxWidgets/wxWidgets/ ... 28ad6186ed
-
- Super wx Problem Solver
- Posts: 488
- Joined: Fri Oct 27, 2006 4:35 pm
- Location: Paris, France
- Contact:
Re: wxArray usage!
@tomay3000
The decision to use wxVector is all yours. However, when quoting your source, you should quote it fully so there is no misunderstanding. The change on github submitted by vadz applies to a specific array, and does not imply that it is the end of array macros.
The decision to use wxVector is all yours. However, when quoting your source, you should quote it fully so there is no misunderstanding. The change on github submitted by vadz applies to a specific array, and does not imply that it is the end of array macros.
Use wxVector<> for wxBookCtrlBase::m_pages array
Get rid of another macro-based array in favour of wxVector<>.
No real changes.
Re: wxArray usage!
To conclude, in your code:
1. Stay away from the old macro-based containers, they are relics of pre-STL times and not to be used.
2. Use standard containers such as std::vector over wxVector and wxArrayString, so you can avoid issues like this.
1. Stay away from the old macro-based containers, they are relics of pre-STL times and not to be used.
2. Use standard containers such as std::vector over wxVector and wxArrayString, so you can avoid issues like this.
Re: wxArray usage!
Is there a official milestone for replacing the old macro-based containers? There are lots of API still using them as input/output.
PB wrote:To conclude, in your code:
1. Stay away from the old macro-based containers, they are relics of pre-STL times and not to be used.
2. Use standard containers such as std::vector over wxVector and wxArrayString, so you can avoid issues like this.
Re: wxArray usage!
No, but i don't think they will be dropped anytime soon. If ever.Is there a official milestone for replacing the old macro-based containers? There are lots of API still using them as input/output.
Use the source, Luke!
Re: wxArray usage!
Just to be sure: As I wrote in my comment the two points concerned your own code, obviously those old containers must be used when calling wxWidgets API.