description | title | ms.date | ms.topic | f1_keywords | ms.assetid | |
---|---|---|---|---|---|---|
Learn more about: Platform::Collections::UnorderedMap Class |
Platform::Collections::UnorderedMap Class |
12/30/2016 |
reference |
|
dc84f261-b13c-4c0a-9b57-30dcb9e3065e |
Represents an unordered map, which is a collection of key-value pairs.
template <
typename K,
typename V,
typename C = std::equal_to<K>
>
ref class Map sealed;
K
The type of the key in the key-value pair.
V
The type of the value in the key-value pair.
C
A type that provides a function object that can compare two element values as sort keys to determine their relative order in the Map. By default, std::equal_to<K>.
Allowed types are:
-
integers
-
interface class^
-
public ref class^
-
value struct
-
public enum class
UnorderedMap is basically a wrapper for std::unordered_map that supports storage of Windows Runtime types. It is the a concrete implementation of the Windows::Foundation::Collections::IMap and IObservableMap types that are passed across public Windows Runtime interfaces. If you try to use a Platform::Collections::UnorderedMap
type in a public return value or parameter, compiler error C3986 is raised. You can fix the error by changing the type of the parameter or return value to Windows::Foundation::Collections::IMap.
For more information, see Collections.
Name | Description |
---|---|
UnorderedMap::UnorderedMap | Initializes a new instance of the Map class. |
Name | Description |
---|---|
UnorderedMap::Clear | Removes all key-value pairs from the current Map object. |
UnorderedMap::First | Returns an iterator that specifies the first element in the map. |
UnorderedMap::GetView | Returns a read-only view of the current Map; that is, a Platform::Collections::UnorderedMapView Class. |
UnorderedMap::HasKey | Determines whether the current Map contains the specified key. |
UnorderedMap::Insert | Adds the specified key-value pair to the current Map object. |
UnorderedMap::Lookup | Retrieves the element at the specified key in the current Map object. |
UnorderedMap::Remove | Deletes the specified key-value pair from the current Map object. |
UnorderedMap::Size | Returns the number of elements in the current Map object. |
Name | Description |
---|---|
Map::MapChanged event | Occurs when the Map changes. |
UnorderedMap
Header: collection.h
Namespace: Platform::Collections
Removes all key-value pairs from the current UnorderedMap object.
virtual void Clear();
Returns an iterator that specifies the first Windows::Foundation::Collections::IKeyValuePair<K,V> element in the unordered map.
virtual Windows::Foundation::Collections::IIterator<
Windows::Foundation::Collections::IKeyValuePair<K, V>^>^
First();
An iterator that specifies the first element in the map.
A convenient way to hold the iterator returned by First() is to assign the return value to a variable that is declared with the auto
type deduction keyword. For example, auto x = myUnorderedMap->First();
.
Returns a read-only view of the current UnorderedMap; that is, an Platform::Collections::UnorderedMapView Class that implements the Windows::Foundation::Collections::IMapView::IMapView interface.
Windows::Foundation::Collections::IMapView<K, V>^ GetView();
An UnorderedMapView
object.
Determines whether the current UnorderedMap contains the specified key.
bool HasKey(
K key
);
key
The key used to locate the UnorderedMap element. The type of key is typename K.
true
if the key is found; otherwise, false
.
Adds the specified key-value pair to the current UnorderedMap object.
virtual bool Insert(
K key,
V value
);
key
The key portion of the key-value pair. The type of key is typename K.
value
The value portion of the key-value pair. The type of value is typename V.
true
if the key of an existing element in the current Map matches key and the value portion of that element is set to value. false
if no existing element in the current Map matches key and the key and value parameters are made into a key-value pair and then added to the current UnorderedMap.
Retrieves the value of type V that is associated with the specified key of type K.
V Lookup(
K key
);
key
The key used to locate an element in the UnorderedMap. The type of key is typename K.
The value that is paired with the key. The type of the return value is typename V.
Raised when an item is inserted into or removed from the map.
event Windows::Foundation::Collections::MapChangedEventHandler<K,V>^ MapChanged;
A MapChangedEventHandler<K,V> that contains information about the object that raised the event, and the kind of change that occurred. See also IMapChangedEventArgs<K> and CollectionChange Enumeration.
Windows Runtime apps that us C# or Visual Basic project IMap<K,V> as IDictionary<K,V>.
Deletes the specified key-value pair from the UnorderedMap object.
virtual void Remove(
K key);
key
The key portion of the key-value pair. The type of key is typename K.
Returns the number of Windows::Foundation::Collections::IKeyValuePair<K,V> elements in the UnorderedMap.
virtual property unsigned int Size;
The number of elements in the Unordered Map.
Initializes a new instance of the UnorderedMap class.
UnorderedMap();
explicit UnorderedMap(
size_t n
);
UnorderedMap(
size_t n,
const H& h
);
UnorderedMap(
size_t n,
const H& h,
const P& p
);
explicit UnorderedMap(
const std::unordered_map<K, V, H, P>& m
);
explicit UnorderedMap(
std::unordered_map<K, V, H, P>&& m
);
template <typename InIt>
UnorderedMap(
InIt first,
InIt last
);
template <typename InIt>
UnorderedMap(
InIt first,
InIt last,
size_t n
);
template <typename InIt>
UnorderedMap(
InIt first,
InIt last,
size_t n,
const H& h
);
template <typename InIt>
UnorderedMap(
InIt first,
InIt last,
size_t n,
const H& h,
const P& p
);
UnorderedMap(
std::initializer_list< std::pair<const K, V>> il
);
UnorderedMap(
std::initializer_list< std::pair<const K, V>> il,
size_t n
);
UnorderedMap(
std::initializer_list< std::pair<const K, V>> il,
size_t n,
const H& h
);
UnorderedMap(
std::initializer_list< std::pair<const K, V>> il,
size_t n,
const H& h,
const P& p
);
InIt
The typename of the current UnorderedMap.
P
A function object that can compare two keys to determine whether they are equal. This parameter defaults to std::equal_to<K>.
H
A function object that produces a hash value for a keys. This parameter defaults to hash Class 1 for the key types that the class supports.
m
A reference or Lvalues and Rvalues to a std::unordered_map that is used to initialize the current UnorderedMap.
il
A std::initializer_list of std::pair objects that is used to initialize the map.
first
The input iterator of the first element in a range of elements used to initialize the current UnorderedMap.
last
The input iterator of the first element after a range of elements used to initialize the current UnorderedMap.
Platform Namespace
Platform::Collections Namespace
Platform::Collections::Map Class
Platform::Collections::UnorderedMapView Class
Collections
Creating Windows Runtime Components in C++