0
bool all_ok = boost::algorithm::all_of(info.begin(), threadInfo.end(), [&](std::pair<std::string, Info> const &p){ return p.second.am_ok; });

Above is a line I am trying to remove c++11 from (in order to be compliant with an application I am integrating with, if you must know). I would like to replace the lambda without defining a function external to the current method.

My question is, how can I utilize boost::bind to represent a function & binding that takes in a single input and returns a boolean?

MM.
  • 4,224
  • 5
  • 37
  • 74
  • 1
    What about this: http://stackoverflow.com/questions/372695/is-there-a-standard-c-function-object-for-taking-apart-a-stdpair (to replace part of the lambda, there's still more to go all the way) – Dan Mašek Feb 25 '17 at 01:01

1 Answers1

0

If you really want to use boost::bind to do this, it would look something like this:

boost::bind(&Info::am_ok, boost::bind(&std::pair<std::string, Info>::second, _1));

Boost.Bind supports composition of its function objects, so in this case the function object created by the nested bind gets called first, and its result (the Info object) is passed to the enclosing function object, which returns the am_ok member of the structure.

You see that the code is somewhat contrived, so you'll probably want to write a custom function object anyway.

struct is_ok
{
    typedef bool result_type;
    result_type operator() (std::pair<std::string, Info> const &p) const
    {
        return p.second.am_ok;
    }
};
Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27