jeudi 2 juin 2016

how to pass a std::bind object to a function

I need to pass a bind function to another function but i am getting error that there is no conversion available-

cannot convert argument 2 from 'std::_Bind<true,std::string,std::string (__cdecl *const )(std::string,std::string),std::string &,std::_Ph<2> &>' to 'std::function<std::string (std::string)> &'

The function:

std::string keyFormatter(std::string sKeyFormat, std::string skey)
{
    boost::replace_all(sKeyFormat, "$ID$", skey);
    return sKeyFormat;
}

The usage is like -

auto fun = std::bind(&keyFormatter, sKeyFormat, std::placeholders::_2);
client(sTopic, fun);

The client function looks like-

void client(std::function<std::string(std::string)> keyConverter)
{
    // do something.
}

Aucun commentaire:

Enregistrer un commentaire