I have a class, called Program, and I want a member function which can take any type of function object (along with arguments as the other arguments), which will be executed after some object specific initialization, and perhaps return the value it was suppossed to.
I can't figure out what to do about the arguments.
I know that it is possible without imposing restrictions on the argument (like it must take a std::tuple).Code:template <typename Function,typename ReturnType> ReturnType Program::useFor(Function foo) { glUseProgram(this->handle); ReturnType value = foo(); glUseProgram(0); return value; }
The design of std::thread's constructor is exactly what I'm aiming for.
Code:auto func = [](int x){std::cout<<x;}; std::thread myThread(func,5);



2Likes
LinkBack URL
About LinkBacks




