public member function
std::list::size
<list>
Return size
Returns the number of elements in the container.
Parameters
none
Return Value
The number of elements that conform the list's content.
Member type
size_type is an unsigned integral type.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
// list::size
#include <iostream>
#include <list>
using namespace std;
int main ()
{
list<int> myints;
cout << "0. size: " << (int) myints.size() << endl;
for (int i=0; i<10; i++) myints.push_back(i);
cout << "1. size: " << (int) myints.size() << endl;
myints.insert (myints.begin(),10,100);
cout << "2. size: " << (int) myints.size() << endl;
myints.pop_back();
cout << "3. size: " << (int) myints.size() << endl;
return 0;
}
|
Output:
0. size: 0
1. size: 10
2. size: 20
3. size: 19
|
Complexity
Constant (recommended). Linear in some implementations.
See also
- list::resize
- Change size (public member function)
- list::max_size
- Return maximum size (public member function)