Re: Is CArray best for this...
Giovanni Dicanio schrieb:
"David Wilkinson" <no-reply@effisols.com> ha scritto nel messaggio
news:uAhouOdWIHA.5208@TK2MSFTNGP04.phx.gbl...
Hi David,
Strangely enough, I wrote the following piece of code just yesterday
typedef std::map<CString, CString> StringMap;
StringMap m_itemMap;
CListBox m_keyListBox;
void CMyDlg::DisplayItems()
{
m_keyListBox.ResetContent();
for (StringMap::const_iterator it = m_itemMap.begin(); it !=
m_itemMap.end(); ++it)
I may misunderstand David C., but I think that he would prefer a "cleaner"
style, like what C# Dictionary offers, e.g.:
Dictionary< string, string > itemMap;
foreach ( string key in itemMap )
{
// Write key ... or add it to list box or whatever
DoSomething( key );
}
If I remember, that code is even wrong, the element type of a Dictionary<> is a
KeyValuePair<> which is not much different from the C++ std::pair<>:
Dictionary< string, string > itemMap;
foreach ( KeyValuePair<string, string> element in itemMap )
{
// Write key ... or add it to list box or whatever
DoSomething( element );
}
And the C++ version can be even shorter:
#include <algorithm>
...
for_each (itemMap.begin(), iremMap.end(), DoSomething);
So he may want a 'foreach' keyword to be added to C++, and kind of "simpler"
collections than STL (however, STL is very powerful).
See, for_each is already there! But it works a little different ...
Norbert