• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2277
  • Last Modified:

Std::set equivalent MFC container

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
Axter
Asked:
Axter
  • 6
  • 4
  • 2
2 Solutions
 
jkrCommented:
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
 
Jaime OlivaresCommented:
I think CMapStringToOb  and CMapStringToPtr classes can give you similar functionality to std::set since it have unique-id feature.
0
 
AxterAuthor Commented:
>>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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jkrCommented:
MFC has vectors, arrays and maps. No lists, no sets, no queues.
0
 
AxterAuthor Commented:
>>No lists, no sets, no queues.

Isn't CList similar to std::list?
0
 
Jaime OlivaresCommented:
CList derived objects are a double linked list implementation
0
 
Jaime OlivaresCommented:
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
 
Jaime OlivaresCommented:
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
 
AxterAuthor Commented:
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
 
Jaime OlivaresCommented:
>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
 
AxterAuthor Commented:
jkr & jaime_olivares,

Thanks
0
 
Jaime OlivaresCommented:
you're welcome. Maybe would be a good idea to write a CSet class for codeproject.com
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now