Reputation: 800
Having a non-empty boost::function
, how to make it empty (so when you call .empty()
on it you'll get true
)?
Upvotes: 3
Views: 3807
Reputation: 1955
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.
Upvotes: 4
Reputation: 55395
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
Upvotes: 4