N
n.torrey.pines
I believe boost::function is part of TR1, so imagine this is a job
interview question in 2009:
Guess how many times ~int_div() is called between "before" and "after"
and explain why. (I was surprised and still don't understand why) :
#include <iostream>
#include <boost/function.hpp>
typedef boost::function2<float, int, int> fun;
struct int_div {
float operator()(int x, int y) const { return ((float)x)/y; }
~int_div() { std::cout << "destructor\n"; }
};
int main() {
int_div i;
fun f;
{
std::cout << "before\n";
f = i;
std::cout << "after\n";
}
}
interview question in 2009:
Guess how many times ~int_div() is called between "before" and "after"
and explain why. (I was surprised and still don't understand why) :
#include <iostream>
#include <boost/function.hpp>
typedef boost::function2<float, int, int> fun;
struct int_div {
float operator()(int x, int y) const { return ((float)x)/y; }
~int_div() { std::cout << "destructor\n"; }
};
int main() {
int_div i;
fun f;
{
std::cout << "before\n";
f = i;
std::cout << "after\n";
}
}