Platform::Collections::VectorView Class

Represents a read-only view of a sequential collection of objects that can be individually accessed by index. The type of each object in the collection is specified by the template parameter.

Syntax

template <typename T, typename E>
   ref class VectorView sealed;

Parameters

T
The type of the elements contained in the VectorView object.

E
Specifies a binary predicate for testing equality with values of type T. The default value is std::equal_to<T>.

Remarks

The VectorView class implements the Windows::Foundation::Collections::IVectorView<T> interface, and support for Standard Template Library iterators.

Members

Public Constructors

Name Description
VectorView::VectorView Initializes a new instance of the VectorView class.

Public Methods

Name Description
VectorView::First Returns an iterator that specifies the first element in the VectorView.
VectorView::GetAt Retrieves the element of the current VectorView that is indicated by the specified index.
VectorView::GetMany Retrieves a sequence of items from the current VectorView, starting at the specified index.
VectorView::IndexOf Searches for the specified item in the current VectorView, and if found, returns the index of the item.
VectorView::Size Returns the number of elements in the current VectorView object.

Inheritance Hierarchy

VectorView

Requirements

Header: collection.h

Namespace: Platform::Collections

VectorView::First Method

Returns an iterator that specifies the first element in the VectorView.

Syntax

virtual Windows::Foundation::Collections::IIterator<T>^
   First();

Return Value

An iterator that specifies the first element in the VectorView.

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

VectorView::GetAt Method

Retrieves the element of the current VectorView that is indicated by the specified index.

Syntax

T GetAt(
   UInt32 index
);

Parameters

index
A zero-based, unsigned integer that specifies a particular element in the VectorView object.

Return Value

The element specified by the index parameter. The element type is specified by the VectorView template parameter, T.

VectorView::GetMany Method

Retrieves a sequence of items from the current VectorView, starting at the specified index.

Syntax

virtual unsigned int GetMany(
   unsigned int startIndex,
   ::Platform::WriteOnlyArray<T>^ dest
);

Parameters

startIndex
The zero-based index of the start of the items to retrieve.

dest
When this operation completes, an array of items that begin at the element specified by startIndex and end at the last element in the VectorView.

Return Value

The number of items retrieved.

VectorView::IndexOf Method

Searches for the specified item in the current VectorView, and if found, returns the index of the item.

Syntax

virtual bool IndexOf(
   T value,
   unsigned int* index
);

Parameters

value
The item to find.

index
The zero-based index of the item if parameter value is found; otherwise, 0.

The index parameter is 0 if either the item is the first element of the VectorView or the item was not found. If the return value is true, the item was found and it is the first element; otherwise, the item was not found.

Return Value

true if the specified item is found; otherwise, false.

VectorView::Size Method

Returns the number of elements in the current VectorView object.

Syntax

virtual property unsigned int Size;

Return Value

The number of elements in the current VectorView.

VectorView::VectorView Constructor

Initializes a new instance of the VectorView class.

Syntax

VectorView();
explicit VectorView(
   UInt32 size
);
VectorView(
   UInt32 size,
   T value
);
explicit VectorView(
   const ::std::vector<T>& v
);
explicit VectorView(
   ::std::vector<T>&& v
);
VectorView(
   const T * ptr,
   UInt32 size
);

template <
   size_t N
>
explicit VectorView(
   const T (&arr)[N]
);

template <
   size_t N
>
explicit VectorView(
   const ::std::array<T,
   N>& a
);

explicit VectorView(
   const ::Platform::Array<T>^ arr
);

template <
   typename InIt
>
VectorView(
   InItfirst,
   InItlast
);

VectorView(
   std::initializer_list<T> il
);

Parameters

InIt
The type of a collection of objects that is used to initialize the current VectorView.

il
A std::initializer_list whose elements will be used to initialize the VectorView.

N
The number of elements in a collection of objects that is used to initialize the current VectorView.

size
The number of elements in the VectorView.

value
A value that is used to initialize each element in the current VectorView.

v
An Lvalues and Rvalues to a std::vector that is used to initialize the current VectorView.

ptr
Pointer to a std::vector that is used to initialize the current VectorView.

arr
A Platform::Array object that is used to initialize the current VectorView.

a
A std::array object that is used to initialize the current VectorView.

first
The first element in a sequence of objects that are used to initialize the current VectorView. The type of first is passed by means of perfect forwarding. For more information, see Rvalue Reference Declarator: &&.

last
The last element in a sequence of objects that are used to initialize the current VectorView. The type of last is passed by means of perfect forwarding. For more information, see Rvalue Reference Declarator: &&.

See also

Platform Namespace
Creating Windows Runtime Components in C++