C++ Deque Library - front() Function


Advertisements

Description

The C++ function std::deque::front() returns a reference to the first element of the deque.

Declaration

Following is the declaration for std::deque::front() function form std::deque header.

C++98

reference front();
const_reference front() const;

Parameters

None

Return value

Returns constant reference if object is constant qualified otherwise non-constant reference.

Exceptions

This member function never throws exception.

Time complexity

Constant i.e. O(1)

Example

The following example shows the usage of std::deque::front() function.

#include <iostream>
#include <deque>

using namespace std;

int main(void) {

   deque<int> d = {1, 2, 3, 4, 5};

   cout << "First element of deque = " << d.front() << endl;

   return 0;
}

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

First element of deque = 1
deque.htm
Advertisements