I have been reading Effective STL by Meyers.
I came across some sections which mention function adapter objects, such as not1, bind1st, bind2nd. There are apparently a range of such function adapter objects, however I have never encountered these before. Another example is mem_fun and mem_fun_ref.
Many of these inherit from unary_function and binary_function. Some links are provided below.
https://en.cppreference.com/w/cpp/utility/functional/unary_function
https://en.cppreference.com/w/cpp/utility/functional/binary_function
https://en.cppreference.com/w/cpp/utility/functional/mem_fun
These objects are depreciated in C++ 11, which probably explains why I had not encountered them before.
Why are they deprecated, and what replaces them? My instinct tells me that a lambda can replace such function objects, and while reading the book it did occur to me that some of the sorting operations on STL containers can be described using a lambda instead of a function object.
- Does a lambda completely replace these "adapter functions".
- If so, are function objects still useful post C++ 11? If they have been made obsolete in the STL, does this mean function objects are obsolete everywhere in C++ 11 or do they still have uses?
As a final comment, are there any modern books on STL which serve as a good replacement for Meyers Effective STL? I have learned a lot from reading his book but there are probably more sections than I currently realize which contain obsolete information.
You can use one of these:
std::bindstd::mem_fnSince C++14, lambdas can do everything that the deprecated and later removed functor templates can do.
Lambdas are function objects.
If you mean to ask whether it's still useful to write named function class templates: Yes, it's still occasionally useful.
Here's an example: