0

Due to the polyvalence of std::bind(&callable, args, placeholders), i ask knowing if we can use it instead of std::mem_fn(&callable/args) without a care, or std::mem_fn has something which makes it legitimate ?

#include <iostream>
#include <functional>

class Clee{
public:


     Clee(){}
     Clee(int data):m_data(data){}
     virtual~Clee(){}

     void callee(){
         std::cout<<"Some Process... "<<std::endl;
     }
protected:
    int m_data;

};

int main()
{

    Clee clee(42);

    auto mfunc = std::mem_fn(&Clee::callee);

    auto bindf = std::bind(&Clee::callee, clee);

    mfunc(clee);
    bindf();

    return 0;
}

Note : I'm asking especially for the difference between them, i'm aware about Lambdas

rekkalmd
  • 171
  • 1
  • 12
  • 1
    You should ditch both and use lambdas instead – bolov Jun 03 '20 at 17:56
  • Thanks for the answer, yes in fact, i forgot to mention to put lambdas aside for this question. – rekkalmd Jun 03 '20 at 17:59
  • 2
    `std::mem_fn` is less verbose where you don't want to provide arguments on binding, that's pretty much it. – George Jun 03 '20 at 18:04
  • 1
    Does this answer your question? (See 1st answer) [What is the difference between std::function and std::mem\_fn](https://stackoverflow.com/questions/30106561/what-is-the-difference-between-stdfunction-and-stdmem-fn) – jtbandes Jun 03 '20 at 18:06

0 Answers0