A base class from which you can derive to implement your own custom view, or span, of a contiguous sequence of elements in a general-purpose collection. For more info, and code examples, see Collections with C++/WinRT.
Syntaxtemplate <typename D, typename T, typename Version = winrt::impl::no_collection_version>
struct vector_view_base : iterable_base<D, T, Version>
Template parameters
typename D
Your derived type name.
typename T
The type of the elements that the vector_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 vector_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 vector_view_base object with a range-based for
statement.
You can also retrieve an IIterator from the vector_view_base::First function, and use that to iterate through the elements viewed by a vector_view_base object.
...
#include <iostream>
using namespace winrt;
using namespace Windows::Foundation::Collections;
...
struct MyVectorView :
implements<MyVectorView, IVectorView<float>, IIterable<float>>,
winrt::vector_view_base<MyVectorView, float>
{
auto& get_container() const noexcept
{
return m_values;
}
private:
std::vector<float> m_values{ 0.1f, 0.2f, 0.3f };
};
...
IVectorView<float> view{ winrt::make<MyVectorView>() };
for (float el : view)
{
std::wcout << el << std::endl;
}
IIterator<float> it{ view.First() };
while (it.HasCurrent())
{
std::wcout << it.Current() << std::endl;
it.MoveNext();
}
vector_view_base::First function
Retrieves an IIterator representing the first element viewed by the vector_view_base object.
Syntaxauto First();
Return value
An IIterator representing the first element viewed by the vector_view_base object.
vector_view_base::GetAt functionRetrieves the element at the specified index viewed by the vector_view_base object.
SyntaxT GetAt(uint32_t const index) const;
Parameters
index
A zero-based element index.
The element at the specified index viewed by the vector_view_base object.
vector_view_base::GetMany functionRetrieves a collection of elements viewed by the vector_view_base object beginning at the given index.
Syntaxuint32_t GetMany(uint32_t const startIndex, array_view<T> values) const;
Parameters
startIndex
A zero-based element index to start at.
values
An array_view to copy the items into.
A value representing the number of elements retrieved.
vector_view_base::IndexOf functionRetrieves the index of a specified element viewed by the vector_view_base object.
Syntaxbool IndexOf(T const& value, uint32_t& index) const noexcept;
Parameters
value
The element, viewed by the vector_view_base object, to look for.
index
The zero-based index of the element if the element is found, otherwise the number of elements viewed by the vector_view_base object.
true
if the element is found, otherwise false
.
Retrieves the number of elements viewed by the vector_view_base object.
Syntaxuint32_t Size() const noexcept;
Return value
A value representing the number of elements viewed by the vector_view_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