I get a compilation error (error C2064: term does not evaluate to function taking 0 arguments
) when compiling this code in visual studio 2013
#include <string>
#include <iostream>
#include <functional>
template<class F>
void foo(F& callback)
{
callback();
}
template<class F>
void bar(F& callback)
{
auto barCallback = std::bind([](F& callback)
{
callback();
std::cout << "world" << std::endl;
}, std::move(callback));
foo(barCallback);
}
int main()
{
std::string s("hello ");
auto f = std::bind([](std::string& s) { std::cout << s; }, std::move(s));
bar(f);
}
Basically, what I am trying to achieve here is to move the std::string
from main
into bar
and then into foo
(without making copies)