Platform::Collections::UnorderedMap Class

Represents an unordered map, which is a collection of key-value pairs.

Syntax

template <
   typename K,
   typename V,
   typename C = std::equal_to<K>
>
ref class Map sealed;

Parameters

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>.

Remarks

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 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.

Members

Public Constructors

Name Description
UnorderedMap::UnorderedMap Initializes a new instance of the Map class.

Public Methods

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.

Events

Name Description
Map::MapChanged event Occurs when the Map changes.

Inheritance Hierarchy

UnorderedMap

Requirements

Header: collection.h

Namespace: Platform::Collections

UnorderedMap::Clear Method

Removes all key-value pairs from the current UnorderedMap object.

Syntax

virtual void Clear();

UnorderedMap::First Method

Returns an iterator that specifies the first Windows::Foundation::Collections::IKeyValuePair<K,V> element in the unordered map.

Syntax

virtual Windows::Foundation::Collections::IIterator<
   Windows::Foundation::Collections::IKeyValuePair<K, V>^>^
   First();

Return Value

An iterator that specifies the first element in the map.

Remarks

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();.

UnorderedMap::GetView Method

Returns a read-only view of the current UnorderedMap; that is, a Platform::Collections::UnorderedMapView Class that implements the Windows::Foundation::Collections::IMapView::IMapView interface.

Syntax

Windows::Foundation::Collections::IMapView<K, V>^ GetView();

Return Value

An UnorderedMapView object.

UnorderedMap::HasKey Method

Determines whether the current UnorderedMap contains the specified key.

Syntax

bool HasKey(
   K key
);

Parameters

key
The key used to locate the UnorderedMap element. The type of key is typename K.

Return Value

true if the key is found; otherwise, false.

UnorderedMap::Insert Method

Adds the specified key-value pair to the current UnorderedMap object.

Syntax

virtual bool Insert(
   K key,
   V value
);

Parameters

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.

Return Value

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.

UnorderedMap::Lookup Method

Retrieves the value of type V that is associated with the specified key of type K.

Syntax

V Lookup(
   K key
);

Parameters

key
The key used to locate an element in the UnorderedMap. The type of key is typename K.

Return Value

The value that is paired with the key. The type of the return value is typename V.

UnorderedMap::MapChanged

Raised when an item is inserted into or removed from the map.

Syntax

event Windows::Foundation::Collections::MapChangedEventHandler<K,V>^ MapChanged;

Property Value/Return Value

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.

.NET Framework Equivalent

Windows Runtime apps that us C# or Visual Basic project IMap<K,V> as IDictionary<K,V>.

UnorderedMap::Remove Method

Deletes the specified key-value pair from the UnorderedMap object.

Syntax

virtual void Remove(
   K key);

Parameters

key
The key portion of the key-value pair. The type of key is typename K.

UnorderedMap::Size Method

Returns the number of Windows::Foundation::Collections::IKeyValuePair<K,V> elements in the UnorderedMap.

Syntax

virtual property unsigned int Size;

Return Value

The number of elements in the Unordered Map.

UnorderedMap::UnorderedMap Constructor

Initializes a new instance of the UnorderedMap class.

Syntax

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
    );

Parameters

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.

See also

Platform Namespace
Platform::Collections Namespace
Platform::Collections::Map Class
Platform::Collections::UnorderedMapView Class
Collections
Creating Windows Runtime Components in C++