C++ List Library - list() Function


Advertisements

Description

The C++ default constructor std::list::list() constructs an empty list with zero elements.

Declaration

Following is the declaration for std::list::list() constructor form std::list header.

C++98

explicit list (const allocator_type& alloc = allocator_type());

C++11

explicit list (const allocator_type& alloc = allocator_type());

Parameters

alloc − Allocator object.

This allocator object is responsible for performing all memory allocation.

Return value

Constructor never returns value.

Exceptions

This member function never throws exception.

Time complexity

Constant i.e. O(1)

Example

The following example shows the usage of std::list::list() constructor.

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l;

   cout << "Size of list = " << l.size() << endl;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

Size of list = 0
list.htm
Advertisements