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

std::dynamic_extent - std::dynamic_extent


Defined in header <span>
inline constexpr std::size_t dynamic_extent = (since C++20)
std::numeric_limits<std::size_t>::max();


std::dynamic_extent is a constant of type std::size_t that is used to differentiate
std::span of static and dynamic extent.


Since std::size_t is an unsigned type, an equivalent definition is:


inline constexpr std::size_t dynamic_extent = -1;


See integral conversions.

// Run this code


#include <array>
#include <cassert>
#include <cstddef>
#include <iostream>
#include <span>
#include <string_view>
#include <vector>


int main()
{
auto print = [](std::string_view const name, std::size_t ex) {
std::cout << name << ", ";
if (ex == std::dynamic_extent) {
std::cout << "dynamic extent\n";
} else {
std::cout << "static extent = " << ex << '\n';
}
};


int a[]{1,2,3,4,5};


std::span span1{a};
print("span1", span1.extent);


std::span<int, std::dynamic_extent> span2{a};
print("span2", span2.extent);


std::array ar{1,2,3,4,5};
std::span span3{ar};
print("span3", span3.extent);


std::vector v{1,2,3,4,5};
std::span span4{v};
print("span4", span4.extent);
}


span1, static extent = 5
span2, dynamic extent
span3, static extent = 5
span4, dynamic extent


span a non-owning view over a contiguous sequence of objects
(C++20) (class template)

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.