A base class from which you can derive to implement your own custom view, or span, of a contiguous sequence of elements in an associative collection. For more info, and code examples, see Collections with C++/WinRT.
Syntaxtemplate <typename D, typename K, typename V, typename Version = winrt::impl::no_collection_version>
struct map_view_base : iterable_base<D, winrt::Windows::Foundation::Collections::IKeyValuePair<K, V>, Version>
Template parameters
typename D
Your derived type name.
typename K
The type of the keys in the collection that the map_view_base views, or spans.
typename V
The type of the values in the collection that the map_view_base views, or spans.
typename Version
A type that provides versioning policy and services to 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_view_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 viewed by a map_view_base object with a range-based for
statement.
You can also retrieve an IIterator from the map_view_base::First function, and use that to iterate through the elements viewed by a map_view_base object.
...
#include <iostream>
using namespace winrt;
using namespace Windows::Foundation::Collections;
...
struct MyMapView :
implements<MyMapView, IMapView<winrt::hstring, int>, IIterable<IKeyValuePair<winrt::hstring, int>>>,
winrt::map_view_base<MyMapView, winrt::hstring, int>
{
auto& get_container() const noexcept
{
return m_values;
}
private:
std::map<winrt::hstring, int> m_values{
{ L"AliceBlue", 0xfff0f8ff }, { L"AntiqueWhite", 0xfffaebd7 }
};
};
...
IMapView<winrt::hstring, int> view{ winrt::make<MyMapView>() };
for (auto const& el : view)
{
std::wcout << el.Key().c_str() << L", " << std::hex << el.Value() << std::endl;
}
IIterator<IKeyValuePair<winrt::hstring, int>> it{ view.First() };
while (it.HasCurrent())
{
std::wcout << it.Current().Key().c_str() << L", " << std::hex << it.Current().Value() << std::endl;
it.MoveNext();
}
map_view_base::First function
Retrieves an IIterator representing the first element viewed by the map_view_base object.
Syntaxauto First();
Return value
An IIterator representing the first element viewed by the map_view_base object.
map_view_base::HasKey functionDetermines whether the specified key belongs to an element viewed by the map_view_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
.
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_view_base::Size functionRetrieves the number of elements viewed by the map_view_base object.
Syntaxuint32_t Size() const noexcept;
Return value
A value representing the number of elements viewed by the map_view_base object.
map_view_base::Split functionSplits the map view into two views.
Syntaxvoid Split(Windows::Foundation::Collections::IMapView<K, V>& first, Windows::Foundation::Collections::IMapView<K, V>& second) const noexcept;
Parameters
first
One half of the original map.
second
The second half of the original map.
RetroSearch 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