C++ Forward_list Library - forward_list() Function



Description

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

Declaration

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

C++11

explicit forward_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::forward_list::forward_list() constructor.

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {
   forward_list<int> fl;

   if (fl.empty())
      cout << "Forward list contains zero elements." << endl;

   return 0;
}

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

Forward list contains zero elements.
forward_list.htm
Advertisements