Having a non-empty boost::function
, how to make it empty (so when you call .empty()
on it you'll get true
)?
Asked
Active
Viewed 3,658 times
3
2 Answers
4
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

jrok
- 54,456
- 9
- 109
- 141
4
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.

Lou
- 1,955
- 14
- 16