Re: Is CArray best for this...
"Giovanni Dicanio" <giovanni.dicanio@invalid.com> wrote in message
news:uZoy$GgWIHA.5348@TK2MSFTNGP03.phx.gbl...
"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 );
}
So he may want a 'foreach' keyword to be added to C++, and kind of
"simpler" collections than STL (however, STL is very powerful).
Thanks G, the C# sample is really ideal, isn't it? I mean look at the "STL
overhead" that is completely absent from C#:
typedef
std::
StringMap::const_iterator
.begin
.end
++it
.first // <-- this is how to access "key"; really bizarre
That's what I meant when I say STL appeals to computer scientists, as they
manage to throw in all manner of extraneous technical gobbly-gook to
accomplish the simplest things.
I also don't like STL behavior that if the element you reference has a
default constructor, referencing the element creates it behind your back,
and if it doesn't have a default constructor, an exception is thrown.
Having different behavior like this is definitely not treating the data type
as a simple extension to the C style [] array and creates errors.
-- David