Remove and remove_if ()
Remove () function
Remove (beg,end,const t& value) // remove interval {beg,end) for each element "equal to value";
Remove is only removed by moving the iterator pointer forward, placing the element that is not deleted in front of the list, and returning an iterator that points to the new, extra-tailed value. Because the Remove () function is not a member, you cannot adjust the length of the linked list. The Remove () function is not really a delete, but you can use the erase () or resize () function to actually delete the element. Use the following:
string " Text with some spaces""), str1.end ()); "Textwithsomespaces"
Function Prototypes:
class class T >const t& value) { = std::find (First, last, value); if (First! = Last ) for (ForwardIt i = first; ++i! = last ; ) if (! (*i = = value) ) *first++ = Std::move (*i); return First ;}
Remove_if() function
Remove_if (Beg, end, op) // remove interval [beg,end) for each "make-to-judge: OP (Elem) obtains true" element;
The parameters of the remove_if (remove and unique are the same) are iterators, the container itself cannot be obtained through iterators, and the elements inside the container can only be removed through the container's member functions, so the Remove series function cannot actually delete the element. You can only move the element that you want to delete to the end of the container and return the iterator to which you want to delete the element, and then delete it by erase the member function. Use the following:
BOOL IsSpace (charreturn';}
string " Text with some spaces"; Str2.erase (remove_if (Str2.begin (), // "Textwithsomespaces"
Function Prototypes:
template<classclass unarypredicate>forwardit remove_if (forwardit First, ForwardIt last, Unarypredicate p) { = std::find_if (First, last, p); if (First! = Last ) for (ForwardIt i = first; ++i! = last ; ) if (!p (*i)) *first++ = Std::move (*i); return First ;}
STL--Remove and remove_if ()