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

std::span::last - std::span::last


template< std::size_t Count >
constexpr std::span<element_type, Count> last() const;
constexpr std::span<element_type, std::dynamic_extent> last( size_type Count )
const;


Obtains a span that is a view over the last Count elements of this span. The program
is ill-formed if Count > Extent. The behavior is undefined if Count > size().


A span r that is a view over the last Count elements of *this, such that r.data() ==
this->data() + (this->size() - Count) && r.size() == Count.

// Run this code


#include <iostream>
#include <span>
#include <string_view>


auto print = [](std::string_view const title, auto const& container) {
std::cout << title << "[" << std::size(container) << "]{ ";
for (auto const& elem : container)
std::cout << elem << ", ";
std::cout << "};\n";
};


void run(std::span<const int> span)
{
print("span: ", span);


std::span<const int, 3> span_last = span.last<3>();
print("span.last<3>(): ", span_last);


std::span<const int, std::dynamic_extent> span_last_dynamic = span.last(2);
print("span.last(2): ", span_last_dynamic);
}


int main()
{
int a[8]{ 1, 2, 3, 4, 5, 6, 7, 8, };
print("int a", a);
run(a);
}


int a[8]{ 1, 2, 3, 4, 5, 6, 7, 8, };
span: [8]{ 1, 2, 3, 4, 5, 6, 7, 8, };
span.last<3>(): [3]{ 6, 7, 8, };
span.last(2): [2]{ 7, 8, };


first obtains a subspan consisting of the first N elements of the sequence
(public member function)
subspan obtains a subspan
(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.