Skip to content

Instantly share code, notes, and snippets.

@kovrov
Created March 17, 2011 15:33
Show Gist options
  • Save kovrov/874530 to your computer and use it in GitHub Desktop.
Save kovrov/874530 to your computer and use it in GitHub Desktop.
#include <qdebug.h>
template <typename T> class Runner;
template <typename T> Runner<T> Closure(T t) { return Runner<T>(t); }
template <typename T> class Runner
{
friend Runner<T> Closure <> (T t);
Runner(T t) : _t (t) {}
T _t;
public:
virtual void exec(float f) { _t(f); }
};
void strategy_function(int i, float f)
{
qDebug() << Q_FUNC_INFO << i << "," << f;
}
int main(int , char *[])
{
int i = 66;
auto callback = Closure([=](float y)
{
return strategy_function(i, y);
});
i = 33;
callback.exec(3.14);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment