forward_list::cbefore_begin() is an inbuilt function in CPP STL which returns a constant random access iterator which points to the position before the first element of the forward_list. The iterator obtained by this function can be used to iterate in the container but cannot be used to modify the content of the object to which it is pointing, even if the object itself is not constant.
Syntax:
forwardlist_name.cbefore_begin()
Parameters: The function does not accept any parameter.
Return value: The function returns a constant random access iterator which points to the position before the first element of the forward_list.
Below program demonstrates the above function:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
forward_list< int > fl = { 20, 30, 40, 50 };
auto it = fl.cbefore_begin();
fl.insert_after(it, 10);
cout << "Element of the list are:" << endl;
for ( auto it = fl.begin(); it != fl.end(); ++it)
cout << *it << " " ;
return 0;
}
|
Output
Element of the list are:
10 20 30 40 50
Time Complexity: O(1)
Auxiliary Space: O(1)
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
28 Jun, 2023
Like Article
Save Article