Having a non-empty boost::function, how to make it empty (so when you call .empty() on it you'll get true)?
Simply assign it NULL or a default constructed boost::function (which are empty by default):
#include <boost/function.hpp>
#include <iostream>
int foo(int) { return 42; }
int main()
{
boost::function<int(int)> f = foo;
std::cout << f.empty();
f = NULL;
std::cout << f.empty();
f = boost::function<int(int)>();
std::cout << f.empty();
}
Output: 011
f.clear() will do the trick. Using the example above
#include <boost/function.hpp>
#include <iostream>
int foo(int) { return 42; }
int main()
{
boost::function<int(int)> f = foo;
std::cout << f.empty();
f.clear();
std::cout << f.empty();
f = boost::function<int(int)>();
std::cout << f.empty();
}
will yield the same result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With