Collections Module
Generic collections, immutable collections, concurrent collections, and ObjectModel.
Generic Collections (System::Collections::Generic)
| Class | Backed by | Notes |
List<T> | std::vector<T> | Dynamic array with .NET API; Add, Remove, Insert, IndexOf, Contains, Sort |
Dictionary<K,V> | std::unordered_map<K,V> | Hash table; Add, Remove, ContainsKey, TryGetValue |
HashSet<T> | std::unordered_set<T> | Add, Remove, Contains, ExceptWith, IntersectWith |
Queue<T> | std::queue<T> | Enqueue, Dequeue, Peek |
Stack<T> | std::stack<T> | Push, Pop, Peek |
SortedDictionary<K,V> | std::map<K,V> | Ordered key-value pairs |
SortedList<K,V> | std::map<K,V> | Sorted by key |
SortedSet<T> | std::set<T> | Sorted, no duplicates |
LinkedList<T> | std::list<T> | Doubly-linked list |
PriorityQueue<T,P> | std::priority_queue | Min-heap by priority |
KeyValuePair<K,V> | Struct | Key/Value pair |
List<T> Example
#include "System/Collections/Generic/List.hpp"
using namespace System::Collections::Generic;
List<int> list;
list.Add(1);
list.Add(2);
list.Add(3);
int count = list.getCountProperty(); // 3
bool has = list.Contains(2); // true
list.Remove(2);
for (auto& item : list) { /* range-for works */ }
Dictionary<K,V> Example
#include "System/Collections/Generic/Dictionary.hpp"
using namespace System::Collections::Generic;
Dictionary<std::string, int> dict;
dict.Add("one", 1);
dict.Add("two", 2);
int val;
if (dict.TryGetValue("one", val)) { /* val = 1 */ }
bool has = dict.ContainsKey("two"); // true
dict.Remove("two");
Immutable Collections (System::Collections::Immutable)
Backed by shared_ptr<const std::container<T>>. Provides value-copy semantics with efficient sharing.
| Class | Header |
ImmutableArray<T> | System/Collections/Immutable/ImmutableArray.hpp |
ImmutableList<T> | System/Collections/Immutable/ImmutableList.hpp |
ImmutableDictionary<K,V> | System/Collections/Immutable/ImmutableDictionary.hpp |
ImmutableHashSet<T> | System/Collections/Immutable/ImmutableHashSet.hpp |
ImmutableQueue<T> | System/Collections/Immutable/ImmutableQueue.hpp |
ImmutableStack<T> | System/Collections/Immutable/ImmutableStack.hpp |
ImmutableSortedDictionary<K,V> | System/Collections/Immutable/ImmutableSortedDictionary.hpp |
ImmutableSortedSet<T> | System/Collections/Immutable/ImmutableSortedSet.hpp |
Concurrent Collections (System::Collections::Concurrent)
| Class | Header | Description |
ConcurrentDictionary<K,V> | System/Collections/Concurrent/ConcurrentDictionary.hpp | Thread-safe dictionary |
ConcurrentQueue<T> | System/Collections/Concurrent/ConcurrentQueue.hpp | Thread-safe FIFO queue |
ConcurrentStack<T> | System/Collections/Concurrent/ConcurrentStack.hpp | Thread-safe LIFO stack |
ObjectModel (System::Collections::ObjectModel)
| Class | Header |
Collection<T> | System/Collections/ObjectModel/Collection.hpp |
ObservableCollection<T> | System/Collections/ObjectModel/ObservableCollection.hpp |
ReadOnlyCollection<T> | System/Collections/ObjectModel/ReadOnlyCollection.hpp |
KeyedCollection<K,T> | System/Collections/ObjectModel/KeyedCollection.hpp |
Non-Generic Collections (System::Collections)
| Class | Header |
ArrayList | System/Collections/ArrayList.hpp |
Hashtable | System/Collections/Hashtable.hpp |
BitArray | System/Collections/BitArray.hpp |
Queue | System/Collections/Queue.hpp |
Stack | System/Collections/Stack.hpp |
Interfaces
All generic collection interfaces have C++ abstract base class equivalents:
IEnumerable<T>, IEnumerator<T>
ICollection<T>
IList<T>
IDictionary<K,V>
ISet<T>
IReadOnlyCollection<T>, IReadOnlyList<T>, IReadOnlyDictionary<K,V>
IComparer<T>, IEqualityComparer<T>