Solved

Please explain std::pair, std::map and std::set statements

Posted on 2006-11-16
1
515 Views
Last Modified: 2008-02-01
Would someone please explain these item by item. Thanks. 100 points each! (I'll increase points as required)


typedef std::pair<CString, NameType> NameEntry;
   std::map<NameEntry, CString> m_oNameMap;
   std::set<CString> m_oUsedNameSet;
0
Comment
Question by:cschene
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 17957594
pair<T1,T2> is a heterogeneous pair: it holds one object of type T1 and one of type T2. (http://www.sgi.com/tech/stl/pair.html)

map<Key, Datais a Sorted Associative Container that associates objects of type Key with objects of type Data. Map is a Pair Associative Container, meaning that its value type is pair<const Key, Data>. (http://www.sgi.com/tech/stl/Map.html)

set<Key, Compare> is a Sorted Associative Container that stores objects of type Key. Set is a Simple Associative Container, meaning that its value type, as well as its key type, is Key (http://www.sgi.com/tech/stl/set.html)

In your code, 'NameEntry' is defined to be a 'std::pair<CString, NameType>', then a map is created that maps such a 'NameEntry' to a string (a MFC CString to be more precise). Finally, there is a set of CStrings, which means a (sorted) collection of CStrings where each entry is unique.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 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

13 Experts available now in Live!

Get 1:1 Help Now