std::remove_if
template <class ForwardIterator, class UnaryPredicate>
ForwardIterator remove_if (ForwardIterator first, ForwardIterator last, UnaryPredicate pred);
My teacher spent long hours in teaching predicate in the std::remove_if algorithm, so far I understand that predicate can be a function or function pointer that return bool or a function object having a bool operator() overload. However, when i learn more and more about STL library, i feel that predicate is a just one out of may kind of "operation" that can be passed to an algorithm. Just list a few more examples:
std::generate
template <class ForwardIterator, class Generator>
void generate (ForwardIterator first, ForwardIterator last, Generator gen);
std::sort
template <class RandomAccessIterator, class Compare>
void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);
std::transform
template <class InputIterator, class OutputIterator, class UnaryOperation>
OutputIterator transform (InputIterator first1, InputIterator last1,
OutputIterator result, UnaryOperation op);
So here we see generator function, compare function, unaryoperation, etc. I believe there are many more. These function of serve different purpose (different return type) by taking in different type and number of input arguments. However, they all appear under different algorithm in the STL, and sometimes i find it confusing and write function incorrectly. Can someone point to me a collection of all the types of functions used by STL for my easier reference? Thank you
Aucun commentaire:
Enregistrer un commentaire