• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2323
  • 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 OlivaresSoftware ArchitectCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
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 OlivaresSoftware ArchitectCommented:
CList derived objects are a double linked list implementation
0
 
Jaime OlivaresSoftware ArchitectCommented:
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 OlivaresSoftware ArchitectCommented:
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 OlivaresSoftware ArchitectCommented:
>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 OlivaresSoftware ArchitectCommented:
you're welcome. Maybe would be a good idea to write a CSet class for codeproject.com
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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