
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
forward_list::remove() in C++ STL
In this article we will be discussing the working, syntax and examples of forward_list::remove() and forward_list::remove_if() functions in C++.
What is a Forward_list in STL?
Forward list are sequence containers that allow constant time insert and erase operations anywhere within the sequence. Forward list are implement as a singly-linked lists. The ordering is kept by the association to each element of a link to the next element in the sequence.
What is forward_list::remove()?
forward_list::remove() is an inbuilt function in C++ STL which is declared in header file. remove() is used to removes all the elements from the forward_list. The container size is decresed by the number of elements removed.
Syntax
flist_container1.remove(const value_type& value );
This function can accept only one parameter, i.e. the value which is to be inserted at the beginning.
Return Value
This function returns nothing
Example
In the below code we are
#include <forward_list> #include <iostream> using namespace std; int main(){ forward_list<int> forwardList = {2, 3, 1, 1, 1, 6, 7}; //List before applying remove operation cout<<"list before applying remove operation : "; for(auto i = forwardList.begin(); i != forwardList.end(); ++i) cout << ' ' << *i; //List after applying remove operation cout<<"\nlist after applying remove operation : "; forwardList.remove(1); for(auto i = forwardList.begin(); i != forwardList.end(); ++i) cout << ' ' << *i; }
Output
If we run the above code it will generate the following output
list before applying remove operation : 2, 3, 1, 1, 1, 6, 7 list after applying remove operation : 2, 3, 6, 7
- Related Articles
- forward_list::begin() and forward_list::end() in C++ STL
- forward_list::front() and forward_list::empty() in C++ STL
- forward_list::push_front() and forward_list::pop_front() in C++ STL
- forward_list::clear() and forward_list::erase_after() in C++ STL
- forward_list cbegin() in C++ STL
- forward_list::cbefore_begin() in C++ STL
- forward_list::unique( ) in C++ STL
- forward_list::swap( ) in C++ STL
- forward_list::reverse( ) in C++ STL
- forward_list merge() in C++ STL
- forward_list::before_begin() in C++ STL
- Forward_list::operator = in C++ STL
- C++ Program to Implement Forward_List in STL
- forward_list emplace_after() and emplace_front() in C++ STL
- forward_list max_size() in C++ STL with Examples
