I'm trying to get along with std::function. From reference here one can see that argument to std::function's ctor should be callable and copy constructible. So here is small example:
#include <iostream>
#include <type_traits>
#include <functional>
class A {
public:
A(int a = 0): a_(a) {}
A(const A& rhs): a_(rhs.a_) {}
A(A&& rhs) = delete;
void operator() ()
{
std::cout << a_ << std::endl;
}
private:
int a_;
};
typedef std::function<void()> Function;
int main(int argc, char *argv[])
{
std::cout << std::boolalpha;
std::cout << "Copy constructible: "
<< std::is_copy_constructible<A>::value << std::endl;
std::cout << "Move constructible: "
<< std::is_move_constructible<A>::value << std::endl;
//Function f = A();
return 0;
}
We have callable, copy constructible but not move constructible class. As I believe this should be sufficient to wrap it in Function. But if you uncomment commented line compiler becomes very upset about deleted move constructor. Here is ideone link. GCC 4.8.0 doesn't compile this too.
So, is it something I misunderstand about std::function or is it GCC's incorrect behaviour?