Can anyone figure out how to make this compile ?
I'm trying to wrap a lambda in another function that does something (here printing "you know what") + calling the lambda.
Best would be to have automatic template parameters deduction.
#include <iostream>
#include <functional>
#include <utility>
void youKnowWhat(const std::function<void()>&& fun)
{
std::cout << "You know what ?" << std::endl;
fun();
}
template <typename... Args>
auto youKnowWhatSomething(const std::function<void(Args...)>&& fun)
{
return [fun{std::move(fun)}](Args... args)
{
youKnowWhat(std::bind(fun, std::forward<Args>(args)...));
};
}
int main()
{
const auto imHavingSomething([](const std::string& s){
std::cout << "Im having " << s << std::endl;
});
const auto youKnowWhatImHavingSomething(youKnowWhatSomething(std::move(imHavingSomething)));
youKnowWhatImHavingSomething("fun with templates");
youKnowWhatImHavingSomething("headaches");
}