Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>std::mem_fun</code> is deprecated. <code>std::mem_fn</code> can do everything it does, and it does it more conveniently. The relation between the two is the same as the relation between <code>std::bind1st</code>/<code>std::bind2nd</code> and the C++11 <code>std::bind</code>. Both <code>std::mem_fn</code> and <code>std::bind</code> were developed and mastered after <code>std::bind1st</code> and <code>std::mem_fun</code> were made into the C++98 Standard. So that means we had to wait until C++11 to properly replace the old stuff with the superior alternatives.</p> <p>For instance, <code>std::mem_fun</code> can only deal with member functions that take one or no argument. <code>std::mem_fn</code> is variadic and can deal with members that take any number of arguments.</p> <p>You also need to pick between <code>std::mem_fun</code> and <code>std::mem_fun_ref</code> depending on whether you want to deal with pointers or references for the class object (respectively). <code>std::mem_fn</code> alone can deal with either, and even provides support for smart pointers.</p> <p>The documentation of <code>boost::mem_fn</code> explains when to use <code>std::mem_fun</code>, and put simply that's when you need to operate with code that expects <code>std::mem_fun</code>, or that expects adaptable functors (which is an obsolete notion* from C++03). For those cases you wouldn't be able to plug in <code>std::mem_fn</code> either, so there you have it: you would use <code>std::mem_fun</code> for legacy.</p> <p>*: I mean by that that new code shouldn't rely on the C++03 protocol of having e.g. <code>result_type</code> member types (it's more customary to use the new traits like <code>std::result_of</code>) -- the new facilities like <code>std::bind</code>/<code>std::mem_fn</code> do in fact provide those members if they would have been present in equivalent C++03 code. I leave it to you to figure out whether you should update old code that relies on adaptable functors with <code>std::mem_fn</code> by relying on this behaviour.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload