The forward_list::assign() is a function in C++ STL which assigns new content to a forward list, replacing its current content and adjusting its size as required.
Version 1:forward_list_name.assign(iterator it1, iterator it2) Version 2:forward_list_name.assign(int n, val) Version 3:forward_list_name.assign(initializer_list li)
Parameters: This function accepts different parameters in different version which are discussed below:
- Iterator: The first version takes two iterators as parameters. New elements are constructed from each element in the range [it1, it2) i.e it includes all elements between it1 and it2 including the element dereferenced by it1 but excluding the element pointed by it2.
- n and val: In the second version n elements are created and each element is initialized with value val.
- Ininitializer_list: In the third version the new contents are created which are initialized with copies of the values passed as initializer list, in the same order.
Return Value This function does not return any value.
The three versions of the function forward_list::assign is illustrated in the following programs:
sample1: 3 3 3 3 3 sample2: 3 3 3 3 3
sample: 4 5 7 8 9 45
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- deque assign() function in C++ STL
- list assign() function in C++ STL
- vector :: assign() in C++ STL
- Conditionally assign a value without using conditional and arithmetic operators
- std::string::assign() in C++
- Programming puzzle (Assign value without any control statement)
- C++ 17 | New ways to Assign values to Variables
- atanh() function in C++ STL
- vector rbegin() and rend() function in C++ STL
- unordered_multimap begin() and end() function in C++ STL
- list cbegin() and cend() function in C++ STL
- bitset all() function in C++ STL
- atan2() function in C++ STL
- list push_back() function in C++ STL
- list back() function in C++ STL
- bitset set() function in C++ STL
- bitset reset() function in C++ STL
- mktime() function in C++ STL
- list remove() function in C++ STL
- list front() function in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.