Re: Is CArray best for this...

Tech-Archive recommends: Speed Up your PC by fixing your registry



David Ching wrote:
Nothing is missing, but what is there appeals to computer scientists and not necessarily to the domain-specific sensibilities of Windows app developers. Iterators have strange syntax, some STL construct (forget which one) needs to reference ".first" and ".second" is totally bizarre, etc. This is completely acceptable, and even desireable, for computer scientists, but not for app writers who are not interested in becoming experts in collections per se, only in that they allow them to write their apps.

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)
{
m_keyListBox.AddString(it->first);
}
}

You see MFC and STL playing nicely together. Yes, you need to know that iterators are like pointers to the elements, and that the elements of std::map are std::pair<Key, Value>, but what is so strange or bizarre about that?

As Norbert says, the concepts used (here iterators and std::pair) are universal to the STL, unlike with CMap, which uses member functions and a nested class CPair that are unique to CMap.

CMap also suffers from the fact that the template arguments ARG_KEY and ARG_VALUE cannot be defaulted to the sensible const KEY& and const VALUE& because the arguments are in the wrong order. I have never understood what the purpose of the double (here quadruple) template argument was, and it was a source of great confusion to me at the beginning.

But we might have to agree to disagree here ...

--
David Wilkinson
Visual C++ MVP
.



Relevant Pages

  • Re: Lists and back() Question.
    ... > linked lists, I assumed endwould return NULL. ... Is there an open source STL I ... Iterators are abstractions of pointers. ... Iterators can become invalid when the container changes. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: OO Style with Ada Containers
    ... cursor/iterator and this is different from both STL and Java (STL ... anyway - in both cases iterators can be used to query as well as to ... algorithms work on whole containers. ...
    (comp.lang.ada)
  • Re: [9fans] a quick and simple minded study of configure.
    ... it is impressive that you typed that on a blackberry! ... I agree as your point is 100% valid that if you don't know distance, ... you need certain restrictions on iterators for STL to work (don't ... stable_sort on list iterators, as you probably need something with random ...
    (comp.os.plan9)
  • Re: Why use STL?
    ... It is more than that in the STL. ... For example sort() requires random iterators to do its job. ... But it also means that if you wrote a brand new container, ...
    (microsoft.public.vc.stl)
  • Re: [Q] Linking woes
    ... One _can_ build application with DDK build environment for sure. ... I use DDK to build everything including huge MFC app with STL. ...
    (microsoft.public.development.device.drivers)