Solved

Std::set equivalent MFC container

Posted on 2004-10-20
12
2,156 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
ID: 12358542
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
ID: 12358920
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
ID: 12359025
>>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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

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

Author Comment

by:Axter
ID: 12359272
>>No lists, no sets, no queues.

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

Expert Comment

by:Jaime Olivares
ID: 12359399
CList derived objects are a double linked list implementation
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12359514
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
ID: 12359711
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
ID: 12360032
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
ID: 12360139
>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
ID: 12361438
jkr & jaime_olivares,

Thanks
0
 
LVL 55

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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