Namespaces
Variants

std::span<T,Extent>:: size

From cppreference.net
constexpr size_type size ( ) const noexcept ;
(depuis C++20)

Retourne le nombre d'éléments dans le span.

Table des matières

Valeur de retour

Le nombre d'éléments dans le span.

Remarque

Macro de test de fonctionnalité Valeur Std Fonctionnalité
__cpp_lib_ssize 201902L (C++20) std::ssize et non signé std::span::size

Exemple

#include <span>
int main()
{
    constexpr static int c_array[]{1, 2, 3, 4, 5, 6, 7, 8};
    constexpr std::span<const int> span{c_array};
    static_assert(8 == span.size());
    static_assert(7 == span.first(7).size());
    static_assert(6 == span.first<6>().size());
    static_assert(5 == span.last(5).size());
    static_assert(4 == span.last<4>().size());
    static_assert(3 == span.subspan(2, 3).size());
    static_assert(2 == span.subspan<3, 2>().size());
    static_assert(1 == span.subspan<7>().size());
}

Voir aussi

construit un span
(fonction membre publique)
retourne la taille de la séquence en octets
(fonction membre publique)