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::span::operator[](3) C++ Standard Libary std::span::operator[](3)

std::span::operator[] - std::span::operator[]


constexpr reference operator[](size_type idx) const;


Returns a reference to the idx-th element of the sequence. The behavior is undefined
if idx is out of range (i.e., if it is greater than or equal to size()).


idx - the index of the element to access


A reference to the idx-th element of the sequence, i.e., data()[idx]


Throws nothing.

// Run this code


#include <iostream>
#include <span>
#include <utility>


void reverse(std::span<int> span) {
for (std::size_t i = 0, j = std::size(span); i < j; ++i) {
--j;
std::swap(span[i], span[j]);
}
}


void print(std::span<const int> const span) {
for (int element: span) {
std::cout << element << ' ';
}
std::cout << '\n';
}


int main() {
int data[]{ 1, 2, 3, 4, 5 };
print(data);
reverse(data);
print(data);
}


1 2 3 4 5
5 4 3 2 1


data returns a pointer to the beginning of the sequence of elements
(public member function)
size returns the number of elements in the sequence
(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.