GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::unique_ptr::operator[](3) C++ Standard Libary std::unique_ptr::operator[](3)

std::unique_ptr::operator[] - std::unique_ptr::operator[]


T& operator[]( std::size_t i ) const; (since C++11)
(constexpr since C++23)


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.


This member function is only provided for specializations for array types.


i - the index of the element to be returned


Returns the element at index i, i.e. get()[i].

// 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';
}
}


0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880


get returns a pointer to the managed object
(public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.