Solved

Std::set equivalent MFC container

Posted on 2004-10-20
12
2,168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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