Solved

Std::set equivalent MFC container

Posted on 2004-10-20
12
2,102 Views
Last Modified: 2013-11-20
Is there an std::set type container in MFC?
I see CMap which is similar to std::map, and CArray, which is similar to std::vector.
And CList, which is similar to std::list.

But I can’t seem to find anything the looks like std::set.

I normally only use std containers, but my current project lead doesn't want me to mix std and MFC.

So before I tell him, there isn't an MFC std::set type container, I want to verify by posting this question.
0
Comment
Question by:Axter
  • 6
  • 4
  • 2
12 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
Comment Utility
You're right, there is none that would offer the functionality of a 'set' - see e.g. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_collections_topics.asp ("Collections Topics")
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 250 total points
Comment Utility
I think CMapStringToOb  and CMapStringToPtr classes can give you similar functionality to std::set since it have unique-id feature.
0
 
LVL 30

Author Comment

by:Axter
Comment Utility
>>I think CMapStringToOb  and CMapStringToPtr classes can give you similar functionality to
>>std::set since it have unique-id feature.

Correct me if I'm wrong, but isn't that just like std::map<string, *obj> ???
In which case, it's not the same.  I'm just looking for a container holding one object like std::set.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
MFC has vectors, arrays and maps. No lists, no sets, no queues.
0
 
LVL 30

Author Comment

by:Axter
Comment Utility
>>No lists, no sets, no queues.

Isn't CList similar to std::list?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
CList derived objects are a double linked list implementation
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
From Bruce Eckel book, Thinking in C++:

Associative containers
-------------------------
The set, map, multiset and multimap are called associative containers because they
associate keys with values. Well, at least maps and multimaps associate keys to values, but
you can look at a set as a map that has no values, only keys (and they can in fact be
implemented this way), and the same for the relationship between multiset and multimap.
So, because of the structural similarity sets and multisets are lumped in with associative
containers.
The most important basic operations with associative containers are putting things in, and in
the case of a set, seeing if something is in the set. In the case of a map, you want to first see if
a key is in the map, and if it exists you want the associated value for that key to be returned.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
That was the theory. In practice, MFC maps have a hash table array and performs linear searches while standard stl set implementations uses a binary tree for fast searching (but not hash), if you have a low count of elements, let's say up to 1000, then there won't be a great difference in performance, so you can derive CSet from CMap, something like:

class CSet : public CMapStringToPtr
0
 
LVL 30

Author Comment

by:Axter
Comment Utility
I'm thinking of using CMapStringToPtr, but it seems too much like a hack.

I'm really surprise that MFC doesn't have a std::set equivalent, considering all they had to do is use most of the implementation of a CMap class, and take away the second type.

FYI:
I'm not a fan of Thinking in C++, because it's misleading, and it has false information.
It's ok for a newbie, but I wouldn't recommend it to an expert.

For example:
>>The set, map, multiset and multimap are called associative containers because they
>>associate keys with values.

That's incorrect, or at least misleading.

According to the C++ standard (ISO/IEC 14882:1998(E))
Section 23.1.2 Associative Containers
Associative containers provide an ability for fast retrieval of data based on keys.

**That's All**
Nothing about associating keys with values, and that's why an std::set container is considered an associative container.




0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
>I'm thinking of using CMapStringToPtr, but it seems too much like a hack.
I have use CMap for this purpose, and also have used CList derived object using Find() method to search if previous object exists.

>I'm not a fan of Thinking in C++, because it's misleading, and it has false information.
>It's ok for a newbie, but I wouldn't recommend it to an expert.
Sorry, it's easy to cut and paste than my C++ books.

0
 
LVL 30

Author Comment

by:Axter
Comment Utility
jkr & jaime_olivares,

Thanks
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
you're welcome. Maybe would be a good idea to write a CSet class for codeproject.com
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 153
repeatSeparator  java  challenge 13 56
move a line in eclipse 3 60
wordcount challenge 11 72
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now