A base class from which you can derive to implement your own custom non-observable associative collection. For more info, and code examples, see Collections with C++/WinRT.
Syntaxtemplate <typename D, typename K, typename V>
struct map_base : map_view_base<D, K, V, winrt::impl::collection_version>
Template parameters
typename D
Your derived type name.
typename K
The type of the keys in the collection.
typename V
The type of the values in the collection.
Minimum supported SDK: Windows SDK version 10.0.17763.0 (Windows 10, version 1809)
Namespace: winrt
Header: %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)
Member functions IteratorsA map_base is a range, and that range is defined by internal free functions (each of which retrieves an iterator) that are compatible with standard language features. Because of this, you can enumerate the elements in a map_base object with a range-based for
statement.
You can also retrieve an IIterator from the map_base::First function, and use that to iterate through the elements in a map_base object.
...
#include <iostream>
using namespace winrt;
using namespace Windows::Foundation::Collections;
...
struct MyMap :
implements<MyMap, IMap<winrt::hstring, int>, IMapView<winrt::hstring, int>, IIterable<IKeyValuePair<winrt::hstring, int>>>,
winrt::map_base<MyMap, winrt::hstring, int>
{
auto& get_container() const noexcept
{
return m_values;
}
auto& get_container() noexcept
{
return m_values;
}
private:
std::map<winrt::hstring, int> m_values{
{ L"AliceBlue", 0xfff0f8ff }, { L"AntiqueWhite", 0xfffaebd7 }
};
};
...
IMap<winrt::hstring, int> map{ winrt::make<MyMap>() };
for (auto const& el : map)
{
std::wcout << el.Key().c_str() << L", " << std::hex << el.Value() << std::endl;
}
IIterator<IKeyValuePair<winrt::hstring, int>> it{ map.First() };
while (it.HasCurrent())
{
std::wcout << it.Current().Key().c_str() << L", " << std::hex << it.Current().Value() << std::endl;
it.MoveNext();
}
map_base::Clear function
Removes all elements from the map_base object.
Syntaxvoid Clear() noexcept;
map_base::First function
Retrieves an IIterator representing the first element in the map_base object.
Syntaxauto First();
Return value
An IIterator representing the first element in the map_base object.
map_base::GetView functionRetrieves an immutable view of the map_base object.
Syntaxwinrt::Windows::Foundation::Collections::IMapView<K, V> GetView() const;
Return value
An IMapView containing an immutable view of the map_base.
map_base::HasKey functionDetermines whether the specified key belongs to an element in the map_base object.
Syntaxbool HasKey(K const& key) const noexcept;
Parameters
key
The key to look for.
true
if an element containing the key is found, otherwise false
.
Inserts or updates an element in the map_base object.
Syntaxbool Insert(K const& key, V const& value);
Parameters
key
The key associated with the element to insert or update.
value
The value to insert or replace.
true
if an element with the specified key was found and updated; otherwise false
.
Looks up the element identified by the specified key, and retrieves the corresponding value.
SyntaxV Lookup(K const& key) const;
Parameters
key
The key to look up.
The value corresponding to the key being looked up if found, otherwise a winrt::hresult_out_of_bounds exception is thrown.
map_base::Remove functionRemoves an element from the map_base object.
Syntaxvoid Remove(K const& key);
Parameters
key
The key associated with the element to remove.
Retrieves the number of elements in the map_base object.
Syntaxuint32_t Size() const noexcept;
Return value
A value representing the number of elements in the map_base object.
See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4