std::unique_ptr<T,Deleter>::operator[] (3) - Linux Manuals
std::unique_ptr<T,Deleter>::operator[]: std::unique_ptr<T,Deleter>::operator[]
Command to display std::unique_ptr<T,Deleter>::operator[]
manual in Linux: $ man 3 std::unique_ptr<T,Deleter>::operator[]
NAME
std::unique_ptr<T,Deleter>::operator[] - std::unique_ptr<T,Deleter>::operator[]
Synopsis
T& operator[](size_t i) const; (since C++11)
operator[] provides access to elements of an array managed by a unique_ptr.
The parameter i shall be less than the number of elements in the array; otherwise, the behavior is undefined.
Parameters
i - the index of the element to be returned
Return value
Returns the element at index i, i.e. get()[i].
Example
// Run this code
#include <iostream>
#include <memory>
int main()
{
const int size = 10;
std::unique_ptr<int[]> fact(new int[size]);
for (int i = 0; i < size; ++i) {
fact[i] = (i == 0) ? 1 : i * fact[i-1];
}
for (int i = 0; i < size; ++i) {
std::cout << i << ": " << fact[i] << '\n';
}
}
Output:
0: 1
1: 1
2: 2
3: 6
4: 24
5: 120
6: 720
7: 5040
8: 40320
9: 362880
See also
returns a pointer to the managed object
get (public member function)
Pages related to std::unique_ptr<T,Deleter>::operator[]
- std::unique_ptr<T,Deleter>::operator<< (3) - std::unique_ptr<T,Deleter>::operator<<
- std::unique_ptr<T,Deleter>::operator= (3) - std::unique_ptr<T,Deleter>::operator=
- std::unique_ptr<T,Deleter>::operatorbool (3) - std::unique_ptr<T,Deleter>::operatorbool
- std::unique_ptr<T,Deleter>::get (3) - std::unique_ptr<T,Deleter>::get
- std::unique_ptr<T,Deleter>::get_deleter (3) - std::unique_ptr<T,Deleter>::get_deleter
- std::unique_ptr<T,Deleter>::release (3) - std::unique_ptr<T,Deleter>::release
- std::unique_ptr<T,Deleter>::reset (3) - std::unique_ptr<T,Deleter>::reset
- std::unique_ptr<T,Deleter>::swap (3) - std::unique_ptr<T,Deleter>::swap
- std::unique_ptr<T,Deleter>::unique_ptr (3) - std::unique_ptr<T,Deleter>::unique_ptr
- std::unique_ptr<T,Deleter>::~unique_ptr (3) - std::unique_ptr<T,Deleter>::~unique_ptr
- std::unique_ptr (3) - std::unique_ptr
- std::unique_copy (3) - std::unique_copy
- std::unique_lock (3) - std::unique_lock
- std::unique_lock<Mutex>::lock (3) - std::unique_lock<Mutex>::lock
- std::unique_lock<Mutex>::mutex (3) - std::unique_lock<Mutex>::mutex
- std::unique_lock<Mutex>::operator= (3) - std::unique_lock<Mutex>::operator=