<iterator>
– funkce
advance
Zvýší iterátor o zadaný počet pozic.
template <class InputIterator, class Distance>
void advance(InputIterator& InIt, Distance Off);
Parametry
InIt
Iterátor, který má být zvýšen a který musí splňovat požadavky pro vstupní iterátor.
Off
Integrální typ, který lze převést na typ rozdílu iterátoru a určuje počet přírůstků pozice, o které má být iterátor zvýšen.
Poznámky
Rozsah musí být nonsingular, kde iterátory musí být dereferenceable nebo za konec.
InputIterator
Pokud splňuje požadavky na obousměrný typ iterátoru, Off
může být negativní. Pokud InputIterator
je typ vstupního nebo předávací iterátoru, Off
musí být neponepatný.
Pokročilá funkce má konstantní složitost, pokud InputIterator
splňuje požadavky iterátoru náhodného přístupu. V opačném případě má lineární složitost, takže je potenciálně nákladná.
Příklad
// iterator_advance.cpp
// compile with: /EHsc
#include <iterator>
#include <list>
#include <iostream>
int main()
{
using namespace std;
list<int> L;
for (int i = 1; i < 9; ++i)
{
L.push_back(i);
}
list<int>::iterator LPOS = L.begin();
cout << "The list L is: ( ";
for (auto L_Iter = L.begin(); L_Iter != L.end(); L_Iter++)
{
cout << *L_Iter << " ";
}
cout << ")." << endl;
cout << "The iterator LPOS initially points to the first element: "
<< *LPOS << "." << endl;
advance(LPOS, 4);
cout << "LPOS is advanced 4 steps forward to point"
<< " to the fifth element: "
<< *LPOS << "." << endl;
advance(LPOS, -3);
cout << "LPOS is moved 3 steps back to point to the "
<< "2nd element: " << *LPOS << "." << endl;
}
The list L is: ( 1 2 3 4 5 6 7 8 ).
The iterator LPOS initially points to the first element: 1.
LPOS is advanced 4 steps forward to point to the fifth element: 5.
LPOS is moved 3 steps back to point to the 2nd element: 2.
back_inserter
Vytvoří iterátor, který může vložit prvky do zadní části zadaného kontejneru.
template <class Container>
back_insert_iterator<Container> back_inserter(Container& Cont);
Parametry
Cont
Kontejner, do kterého se má provést vložení zpět.
Návratová hodnota
Přidruženo back_insert_iterator
k objektu Cont
kontejneru .
Poznámky
Ve standardní knihovně jazyka C++ musí argument odkazovat na jeden ze tří sekvencí kontejnerů, které mají členská funkcepush_back
:deque
Třída, list
třída nebo vector
třída.
Příklad
// iterator_back_inserter.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main()
{
using namespace std;
vector<int> vec;
for (int i = 0; i < 3; ++i)
{
vec.push_back(i);
}
cout << "The initial vector vec is: ( ";
for (auto vIter = vec.begin(); vIter != vec.end(); vIter++)
{
cout << *vIter << " ";
}
cout << ")." << endl;
// Insertions can be done with template function
back_insert_iterator<vector<int> > backiter(vec);
*backiter = 30;
backiter++;
*backiter = 40;
// Alternatively, insertions can be done with the
// back_insert_iterator member function
back_inserter(vec) = 500;
back_inserter(vec) = 600;
cout << "After the insertions, the vector vec is: ( ";
for (auto vIter = vec.begin(); vIter != vec.end(); vIter++)
{
cout << *vIter << " ";
}
cout << ")." << endl;
}
The initial vector vec is: ( 0 1 2 ).
After the insertions, the vector vec is: ( 0 1 2 30 40 500 600 ).
begin
Načte iterátor na první prvek v zadaném kontejneru.
template <class Container>
auto begin(Container& cont) `
-> decltype(cont.begin());
template <class Container>
auto begin(const Container& cont) `
-> decltype(cont.begin());
template <class Ty, class Size>
Ty *begin(Ty (& array)[Size]);
Parametry
cont
Kontejner.
array
Pole objektů typu Ty
.
Návratová hodnota
První dvě funkce šablony vrátí cont.begin()
. První funkce není konstantní, druhá je konstantní.
Třetí funkce šablony vrátí array
.
Příklad
Tuto funkci šablony doporučujeme použít místo člena begin()
kontejneru, pokud je vyžadováno obecnější chování.
// cl.exe /EHsc /nologo /W4 /MTd
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <vector>
template <typename C> void reverse_sort(C& c)
{
std::sort(std::begin(c), std::end(c), std::greater<>());
}
template <typename C> void print(const C& c)
{
for (const auto& e : c)
{
std::cout << e << " ";
}
std::cout << "\n";
}
int main()
{
std::vector<int> v = { 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 };
print(v);
reverse_sort(v);
print(v);
std::cout << "--\n";
int arr[] = { 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1 };
print(arr);
reverse_sort(arr);
print(arr);
}
11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
52 40 34 26 20 17 16 13 11 10 8 5 4 2 1
--
23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1
160 106 80 70 53 40 35 23 20 16 10 8 5 4 2 1
Funkce reverse_sort
podporuje kontejnery libovolného druhu, kromě běžných polí, protože volá nečlenovou verzi begin()
. Kódování reverse_sort
pro použití člena begin()
kontejneru:
template <typename C>
void reverse_sort(C& c) {
using std::begin;
using std::end;
std::sort(c.begin(), c.end(), std::greater<>());
}
Odeslání pole do něj způsobí tuto chybu kompilátoru:
error C2228: left of '.begin' must have class/struct/union
cbegin
Načte iterátor const (jen pro čtení) na první prvek v zadaném kontejneru.
template <class Container>
auto cbegin(const Container& cont)
-> decltype(cont.begin());
Parametry
cont
Kontejner nebo initializer_list
.
Návratová hodnota
Konstanta cont.begin()
.
Poznámky
Tato funkce funguje se všemi kontejnery standardní knihovny C++ a s initializer_list
.
Tuto členská funkce můžete použít místo begin()
funkce šablony, abyste zajistili, že návratová hodnota je const_iterator
. Obvykle se používá s klíčovým slovem odpočtu auto
typu, jak je znázorněno v následujícím příkladu. V tomto příkladu zvažte Container
, že se jedná o upravitelný (non- const
) kontejner nebo initializer_list
jakýkoli druh, který podporuje begin()
a cbegin()
.
auto i1 = Container.begin();
// i1 is Container<T>::iterator
auto i2 = Container.cbegin();
// i2 is Container<T>::const_iterator
cend
Načte iterátor const (jen pro čtení) do elementu, který následuje za posledním prvkem v zadaném kontejneru.
template <class Container>
auto cend(const Container& cont)
-> decltype(cont.end());
Parametry
cont
Kontejner nebo initializer_list
.
Návratová hodnota
Konstanta cont.end()
.
Poznámky
Tato funkce funguje se všemi kontejnery standardní knihovny C++ a s initializer_list
.
Tuto členská funkce můžete použít místo end()
funkce šablony, abyste zajistili, že návratová hodnota je const_iterator
. Obvykle se používá s klíčovým slovem odpočtu auto
typu, jak je znázorněno v následujícím příkladu. V tomto příkladu zvažte Container
, že se jedná o upravitelný (non- const
) kontejner nebo initializer_list
jakýkoli druh, který podporuje end()
a cend()
.
auto i1 = Container.end();
// i1 is Container<T>::iterator
auto i2 = Container.cend();
// i2 is Container<T>::const_iterator
crbegin
Získejte iterátor jen pro čtení k prvkům kontejneru počínaje koncem kontejneru.
template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));
Parametry
C
Typ kontejneru.
c
Instance kontejneru.
Vrácená hodnota
Tento iterátor vrátí prvky kontejneru v obráceném pořadí počínaje koncem kontejneru.
Příklad: crbegin
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v{10, 20, 30};
for (auto i = std::crbegin(v); i != std::crend(v); ++i)
{
std::cout << *i << ' '; // outputs 30 20 10
}
// v[1] = 100; // error because the iterator is const
}
30 20 10
crend
Získejte sentinel na konci obrácené sekvence prvků jen pro čtení.
template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));
Parametry
C
Typ kontejneru.
c
Instance kontejneru.
Vrácená hodnota
Sentinel se řídí posledním prvkem v obráceném zobrazení kontejneru.
crend
příklad
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v{10, 20, 30};
auto vi = std::crend(v);
--vi; // get off the sentinel and onto the last element in the reversed range
std::cout << *vi; // outputs 10
// vi[0] = 300; // error because the iterator is const
}
10
data
Získejte ukazatel na první prvek v kontejneru.
1) template <class C> constexpr auto data(C& c) -> decltype(c.data());
2) template <class C> constexpr auto data(const C& c) -> decltype(c.data());
3) template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;
4) template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
Parametry
C
Typ kontejneru.
c
Instance kontejneru.
E
Typ prvku seznamu inicializátoru.
il
Seznam inicializátorů.
N
Počet prvků v poli.
T
Typ dat v poli.
Vrácená hodnota
1, 2) Ukazatel na základě typu kontejneru na první prvek. Například pokud je kontejner vektorem celých čísel, typ návratové hodnoty je .int *
3) Ukazatel na první prvek jako pole.
4) Ukazatel na první prvek seznamu inicializátoru.
Příklad: data
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v{ 10, 20, 30 };
std::string src{ "a string" };
const char *charPtr = std::data(src);
int* intPtr = std::data(v);
std::cout << charPtr << ", " << *intPtr << '\n'; // a string, 10
}
a string, 10
distance
Určuje počet kroků mezi polohami řešenými dvěma iterátory.
template <class InputIterator>
typename iterator_traits<InputIterator>::difference_type distance(InputIterator first, InputIterator last);
Parametry
first
První iterátor, jehož vzdálenost od druhého je určena.
last
Druhý iterátor, jehož vzdálenost od prvního je určena.
Návratová hodnota
Počet, first
kolikrát se musí zvýšit, dokud se nerovná last
.
Poznámky
Funkce vzdálenosti má konstantní složitost, pokud InputIterator
splňuje požadavky iterátoru náhodného přístupu. V opačném případě má lineární složitost a proto je potenciálně nákladná.
Příklad
// iterator_distance.cpp
// compile with: /EHsc
#include <iterator>
#include <list>
#include <iostream>
int main()
{
using namespace std;
list<int> L;
for (int i = -1; i < 9; ++i)
{
L.push_back(2 * i);
}
list <int>::iterator L_Iter, LPOS = L.begin();
cout << "The list L is: ( ";
for (L_Iter = L.begin(); L_Iter != L.end(); L_Iter++)
{
cout << *L_Iter << " ";
}
cout << ")." << endl;
cout << "The iterator LPOS initially points to the first element: "
<< *LPOS << "." << endl;
advance(LPOS, 7);
cout << "LPOS is advanced 7 steps forward to point "
<< " to the eighth element: "
<< *LPOS << "." << endl;
list<int>::difference_type Ldiff;
Ldiff = distance(L.begin(), LPOS);
cout << "The distance from L.begin( ) to LPOS is: "
<< Ldiff << "." << endl;
}
The list L is: ( -2 0 2 4 6 8 10 12 14 16 ).
The iterator LPOS initially points to the first element: -2.
LPOS is advanced 7 steps forward to point to the eighth element: 12.
The distance from L.begin( ) to LPOS is: 7.
empty
template <class C> constexpr auto empty(const C& c) -> decltype(c.empty());
template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;
template <class E> constexpr bool empty(initializer_list<E> il) noexcept;
Parametry
C
Typ kontejneru.
c
Instance kontejneru.
E
Typ prvku seznamu inicializátoru.
il
Seznam inicializátorů.
N
Počet prvků v poli.
T
Typ dat v poli.
Vrácená hodnota
Vrátí true
, pokud kontejner neobsahuje žádné prvky; jinak false
.
Příklad
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v{ 10,20,30 };
std::vector<int> v2;
std::cout << std::boolalpha << std::empty(v); // outputs false
std::cout << std::boolalpha << ", " << std::empty(v2); // outputs true
}
false, true
end
Načte iterátor na prvek, který následuje po posledním prvku v zadaném kontejneru.
template <class Container>
auto end(Container& cont)
-> decltype(cont.end());
template <class Container>
auto end(const Container& cont)
-> decltype(cont.end());
template <class Ty, class Size>
Ty *end(Ty (& array)[Size]);
Parametry
cont
Kontejner.
array
Pole objektů typu Ty
.
Návratová hodnota
První dvě funkce šablony se vrátí cont.end()
(první není konstantní a druhá je konstantní).
Třetí funkce šablony vrátí array + Size
.
Poznámky
Příklad kódu najdete v tématu begin
.
front_inserter
Vytvoří iterátor, který může vložit prvky do přední části zadaného kontejneru.
template <class Container>
front_insert_iterator<Container> front_inserter(Container& Cont);
Parametry
Cont
Objekt kontejneru, jehož přední strana má vložený prvek.
Návratová hodnota
Přidruženo front_insert_iterator
k objektu Cont
kontejneru .
Poznámky
Členské funkce front_insert_iterator třídy front_insert_iterator lze použít také.
V rámci standardní knihovny jazyka C++ musí argument odkazovat na jeden ze dvou sekvencí kontejnerů, které mají členská funkce push_back
: deque Class nebo "list Class".
Příklad
// iterator_front_inserter.cpp
// compile with: /EHsc
#include <iterator>
#include <list>
#include <iostream>
int main()
{
using namespace std;
list<int> L;
for (int i = -1; i < 9; ++i)
{
L.push_back(i);
}
cout << "The list L is:\n ( ";
for (auto L_Iter = L.begin(); L_Iter != L.end(); L_Iter++)
{
cout << *L_Iter << " ";
}
cout << ")." << endl;
// Using the template function to insert an element
front_insert_iterator<list <int>> Iter(L);
*Iter = 100;
// Alternatively, you may use the front_insert member function
front_inserter(L) = 200;
cout << "After the front insertions, the list L is:\n ( ";
for (auto L_Iter = L.begin(); L_Iter != L.end(); L_Iter++)
{
cout << *L_Iter << " ";
}
cout << ")." << endl;
}
The list L is:
( -1 0 1 2 3 4 5 6 7 8 ).
After the front insertions, the list L is:
( 200 100 -1 0 1 2 3 4 5 6 7 8 ).
inserter
Pomocná funkce šablony, která umožňuje místo inserter(Cont, Where)
insert_iterator<Container>(Cont, Where)
.
template <class Container>
insert_iterator<Container>
inserter(
Container& Cont,
typename Container::iterator Where);
Parametry
Cont
Kontejner, do kterého se mají přidat nové prvky.
Where
Iterátor, který se nachází v místě vložení.
Poznámky
Funkce šablony vrátí insert_iterator
<Container>(Cont, Where)
.
Příklad
// iterator_inserter.cpp
// compile with: /EHsc
#include <iterator>
#include <list>
#include <iostream>
int main()
{
using namespace std;
list<int> L;
for (int i = 2; i < 5; ++i)
{
L.push_back(10 * i);
}
cout << "The list L is:\n ( ";
for (auto L_Iter = L.begin(); L_Iter != L.end(); L_Iter++)
{
cout << *L_Iter << " ";
}
cout << ")." << endl;
// Using the template version to insert an element
insert_iterator<list<int>> Iter(L, L.begin());
*Iter = 1;
// Alternatively, using the member function to insert an element
inserter(L, L.end()) = 500;
cout << "After the insertions, the list L is:\n ( ";
for (auto L_Iter = L.begin(); L_Iter != L.end(); L_Iter++)
{
cout << *L_Iter << " ";
}
cout << ")." << endl;
}
The list L is:
( 20 30 40 ).
After the insertions, the list L is:
( 1 20 30 40 500 ).
make_checked_array_iterator
Vytvoří checked_array_iterator , kterou můžou používat jiné algoritmy.
Poznámka:
Tato funkce je rozšířením standardní knihovny C++ od Microsoftu. Kód implementovaný pomocí této funkce není přenosný do standardního prostředí pro sestavování v jazyce C++, která toto rozšíření společnosti Microsoft nepodporují.
template <class Iter>
checked_array_iterator<Iter>
make_checked_array_iterator(
Iter Ptr,
size_t Size,
size_t Index = 0);
Parametry
Ptr
Ukazatel na cílové pole.
Size
Velikost cílového pole.
Index
Volitelný index do pole.
Návratová hodnota
Instance .checked_array_iterator
Poznámky
Funkce make_checked_array_iterator
je definována stdext
v oboru názvů.
Tato funkce přebírá nezpracovaný ukazatel, který by obvykle způsoboval obavy o přetečení hranic, a zabalí ho do třídy checked_array_iterator , která provádí kontrolu. Vzhledem k tomu, že je tato třída označena jako zaškrtnutá, standardní knihovna C++ o ní nevaruje. Další informace a příklady kódu naleznete v tématu Kontrolované iterátory.
Příklad
V následujícím příkladu se vytvoří vektor a naplní se 10 položkami. Obsah vektoru se zkopíruje do pole pomocí algoritmu kopírování a pak make_checked_array_iterator
se použije k určení cíle. Následuje úmyslné porušení kontroly hranic, aby se spustilo selhání kontrolního výrazu ladění.
// make_checked_array_iterator.cpp
// compile with: /EHsc /W4 /MTd
#include <algorithm>
#include <iterator> // stdext::make_checked_array_iterator
#include <memory> // std::make_unique
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template <typename C> void print(const string& s, const C& c)
{
cout << s;
for (const auto& e : c)
{
cout << e << " ";
}
cout << endl;
}
int main()
{
const size_t dest_size = 10;
// Old-school but not exception safe, favor make_unique<int[]>
// int* dest = new int[dest_size];
unique_ptr<int[]> updest = make_unique<int[]>(dest_size);
int* dest = updest.get(); // get a raw pointer for the demo
vector<int> v;
for (int i = 0; i < dest_size; ++i)
{
v.push_back(i);
}
print("vector v: ", v);
copy(v.begin(), v.end(), stdext::make_checked_array_iterator(dest, dest_size));
cout << "int array dest: ";
for (int i = 0; i < dest_size; ++i)
{
cout << dest[i] << " ";
}
cout << endl;
// Add another element to the vector to force an overrun.
v.push_back(10);
// ! The next line causes a debug assertion when it executes.
copy(v.begin(), v.end(), stdext::make_checked_array_iterator(dest, dest_size));
}
make_move_iterator
Vytvoří move iterator
iterátor, který obsahuje zadaný iterátor.stored
template <class Iterator>
move_iterator<Iterator>
make_move_iterator(const Iterator& It);
Parametry
It
Iterátor uložený v novém iterátoru přesunutí.
Poznámky
Funkce šablony vrátí move_iterator
<Iterator>(_It)
.
make_unchecked_array_iterator
Vytvoří unchecked_array_iterator, kterou můžou používat jiné algoritmy.
Poznámka:
Tato funkce je rozšířením standardní knihovny C++ od Microsoftu. Kód implementovaný pomocí této funkce není přenosný do standardního prostředí pro sestavování v jazyce C++, která toto rozšíření společnosti Microsoft nepodporují.
template <class Iter>
unchecked_array_iterator<Iter>
make_unchecked_array_iterator(Iter Ptr);
Parametry
Ptr
Ukazatel na cílové pole.
Návratová hodnota
Instance .unchecked_array_iterator
Poznámky
Funkce make_unchecked_array_iterator
je definována stdext
v oboru názvů.
Tato funkce vezme nezpracovaný ukazatel a zabalí ho do třídy, která neprovádí žádnou kontrolu, a proto ji optimalizuje na nic, ale také mlčí upozornění kompilátoru, jako je C4996. Proto se jedná o cílený způsob řešení upozornění nekontrolovaného ukazatele bez jejich globálního umlčení nebo nákladů na kontrolu. Další informace a příklady kódu naleznete v tématu Kontrolované iterátory.
Příklad
V následujícím příkladu se vytvoří vektor a naplní se 10 položkami. Obsah vektoru se zkopíruje do pole pomocí algoritmu kopírování a pak make_unchecked_array_iterator
se použije k určení cíle.
// make_unchecked_array_iterator.cpp
// compile with: /EHsc /W4 /MTd
#include <algorithm>
#include <iterator> // stdext::make_unchecked_array_iterator
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template <typename C> void print(const string& s, const C& c)
{
cout << s;
for (const auto& e : c)
{
cout << e << " ";
}
cout << endl;
}
int main()
{
const size_t dest_size = 10;
int* dest = new int[dest_size];
vector<int> v;
for (int i = 0; i < dest_size; ++i)
{
v.push_back(i);
}
print("vector v: ", v);
// COMPILER WARNING SILENCED: stdext::unchecked_array_iterator is marked as checked in debug mode
// (it performs no checking, so an overrun will trigger undefined behavior)
copy(v.begin(), v.end(), stdext::make_unchecked_array_iterator(dest));
cout << "int array dest: ";
for (int i = 0; i < dest_size; ++i)
{
cout << dest[i] << " ";
}
cout << endl;
delete[] dest;
}
vector v: 0 1 2 3 4 5 6 7 8 9
int array dest: 0 1 2 3 4 5 6 7 8 9
next
Iteruje zadaný počet iterací a vrátí novou pozici iterace.
template <class InputIterator>
InputIterator next(
InputIterator first,
typename iterator_traits<InputIterator>::difference_type off = 1);
Parametry
first
Aktuální pozice.
off
Počet opakování.
Návratová hodnota
Vrátí novou pozici iterátoru po iterování off
časů.
Poznámky
Funkce šablony vrací next
přírůstkové off
časy.
prev
Iteruje v opačném pořadí zadaný počet iterací a vrátí novou pozici iterace.
template <class BidirectionalIterator>
BidirectionalIterator prev(
BidirectionalIterator first,
typename iterator_traits<BidirectionalIterator>::difference_type off = 1);
Parametry
first
Aktuální pozice.
off
Počet opakování.
Poznámky
Funkce šablony vrací next
dekrementované off
časy.
rbegin
Získejte iterátor, který vrátí prvky kontejneru v obráceném pořadí.
template <class C> constexpr auto rbegin(C& c) -> decltype(c.rbegin());
template <class C> constexpr auto rbegin(const C& c) -> decltype(c.rbegin());
Parametry
C
Typ kontejneru.
c
Instance kontejneru.
Vrácená hodnota
Vrácený iterátor představuje prvky kontejneru v obráceném pořadí počínaje koncem obráceného rozsahu.
Příklad: rbegin
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v{ 10, 20, 30 };
for (auto e = std::rbegin(v); e != std::rend(v); ++e)
{
std::cout << *e << ' '; // outputs 30 20 10
}
}
30 20 10
rend
Získejte sentinel na konci obrácené sekvence prvků.
template <class C> constexpr auto rend(C& c)-> decltype(c.rend());
template <class C> constexpr auto rend(const C& c) -> decltype(c.rend());
Parametry
C
Typ kontejneru.
c
Instance kontejneru.
Vrácená hodnota
Reverzní iterátor pro sentinel na konci kontejneru. Sentinel se řídí posledním prvkem v obráceném zobrazení kontejneru:
rend
příklad
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v{10, 20, 30};
auto vi = std::rend(v);
--vi; // get off the sentinel and onto the last element in the reversed range
std::cout << *vi; // outputs 10
}
10
size
template <class C> constexpr auto size(const C& c)
-> decltype(c.size());
template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept;
Parametry
C
Typ kontejneru.
c
Instance kontejneru.
N
Počet prvků v poli.
T
Typ dat v poli.
Vrácená hodnota
Počet prvků v kontejneru jako celočíselná hodnota bez znaménka.
Příklad: size
#include <vector>
#include <iostream>
int main()
{
std::vector<int> v{ 10, 20, 30 };
size_t s = std::size(v);
std::cout << s; // outputs 3
}
3