mercredi 3 juin 2020

Can std::bind(&callable, args) replace std::mem_fn(&callable)

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;
}

Aucun commentaire:

Enregistrer un commentaire