A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../container/span/dynamic_extent.html below:

std::dynamic_extent - cppreference.com

std::dynamic_extent is a constant of type std::size_t that is generally used to indicate that any type using std::dynamic_extent will dynamically store its value (e.g., size) rather than having the value statically known in the type.

It is being used in several contexts:

(since C++23) (since C++26) [edit] Note

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

See integral conversions.

[edit] Example
#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 (std::dynamic_extent == ex)
            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);
}

Output:

span1, static extent = 5
span2, dynamic extent
span3, static extent = 5
span4, dynamic extent
[edit] See also a non-owning view over a contiguous sequence of objects
(class template) [edit] a descriptor of a multidimensional index space of some rank
(class template) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4