Appendix B. Migration Cheat Sheet

STL to Generics

STL

.NET Generics class

Comments

vector

List<T>

 

deque

LinkedList<T>

deque allows addition and deletion at both ends in constant time.

list

LinkedList<T>

list also allows addition and deletion at both ends in constant time. Thus, that is what is best mapped to these two containers.

stack

Stack<T>

 

Queue

Queue<T>

 

priority_queue

Not available

You can use PriorityQueue<TKey,TValue> described in Chapter 3, Dictionaries.

set

HashSet<T>, SortedSet<T>

Use SortedSet<T> if you always want the set to be sorted.

multiset

Not available. You can use OrderedBag from PowerCollections.

Can be modeled as Dictionary<T,int> or SortedDictionary<T,int> ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.