#include <iostream>
#include <functional>
template <typename UnaryFunction>
class ApplyValues
{
typedef std::function<UnaryFunction> Performer;
Performer performer;
public:
typedef typename Performer::argument_type argument_type;
ApplyValues( Performer p ) : performer( p ) { }
void apply( argument_type low, argument_type up ) {
performer( low ); performer( up );
}
};
void print(double value) {
std::cout << value << std::endl;
}
struct print2 {
void operator()(double value) {
std::cout << 2 * value << std::endl;
}
};
int main() {
using namespace std;
ApplyValues<void(double)> a(print);
a.apply( 1, 99 );
cout << "---" << endl;
ApplyValues<void(double)> b( (print2()) );
b.apply( 2, 99 );
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KIAp0ZW1wbGF0ZSA8dHlwZW5hbWUgVW5hcnlGdW5jdGlvbj4KY2xhc3MgQXBwbHlWYWx1ZXMKewogICAgdHlwZWRlZiBzdGQ6OmZ1bmN0aW9uPFVuYXJ5RnVuY3Rpb24+IFBlcmZvcm1lcjsKICAgIFBlcmZvcm1lciBwZXJmb3JtZXI7ICAgIApwdWJsaWM6IAogICAgdHlwZWRlZiB0eXBlbmFtZSBQZXJmb3JtZXI6OmFyZ3VtZW50X3R5cGUgYXJndW1lbnRfdHlwZTsKIAogICAgQXBwbHlWYWx1ZXMoIFBlcmZvcm1lciBwICkgOiBwZXJmb3JtZXIoIHAgKSB7IH0KIAogICAgdm9pZCBhcHBseSggYXJndW1lbnRfdHlwZSBsb3csIGFyZ3VtZW50X3R5cGUgdXAgKSB7CiAgICAgICAgcGVyZm9ybWVyKCBsb3cgKTsgcGVyZm9ybWVyKCB1cCApOwogICAgfQp9OwogCnZvaWQgcHJpbnQoZG91YmxlIHZhbHVlKSB7CiAgIHN0ZDo6Y291dCA8PCB2YWx1ZSA8PCBzdGQ6OmVuZGw7Cn0KIApzdHJ1Y3QgcHJpbnQyIHsKICAgdm9pZCBvcGVyYXRvcigpKGRvdWJsZSB2YWx1ZSkgewogICAgICBzdGQ6OmNvdXQgPDwgMiAqIHZhbHVl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