#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgoKY2xhc3MgQSB7CnB1YmxpYzoKICAgIEEoaW50IGEgPSAwKTogYV8oYSkge30KICAgIEEoY29uc3QgQSYgcmhzKTogYV8ocmhzLmFfKSB7fQogICAgQShBJiYgcmhzKSA9IGRlbGV0ZTsKICAgIHZvaWQgb3BlcmF0b3IoKSAoKQogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCBhXyA8PCBzdGQ6OmVuZGw7CiAgICB9Cgpwcml2YXRlOgogICAgaW50IGFfOwp9OwoKdHlwZWRlZiBzdGQ6OmZ1bmN0aW9uPHZvaWQoKT4gRnVuY3Rpb247CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CiAgICBzdGQ6OmNvdXQgPDwgc3RkOjpib29sYWxwaGE7CiAgICBzdGQ6OmNvdXQgPDwgIkNvcHkgY29uc3RydWN0aWJsZTogIgogICAgICAgICAgICAgIDw8IHN0ZDo6aXNfY29weV9jb25zdHJ1Y3RpYmxlPEE+Ojp2YWx1ZSA8PCBzdGQ6OmVuZGw7CiAgICBzdGQ6OmNvdXQgPDwgIk1vdmUgY29uc3RydWN0aWJsZTogIgogICAgICAgICAgICAgIDw8IHN0ZDo6aXNfbW92ZV9jb25zdHJ1Y3RpYmxlPEE+Ojp2YWx1ZSA8PCBzdGQ6OmVuZGw7CiAgICBGdW5jdGlvbiBmID0gQSgpOwogICAgcmV0dXJuIDA7Cn0=
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:28:20: error: use of deleted function ‘A::A(A&&)’
prog.cpp:9:5: error: declared here
In file included from prog.cpp:3:0:
/usr/include/c++/4.7/functional:2288:7: error: initializing argument 1 of ‘std::function<_Res(_ArgTypes ...)>::function(_Functor, typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>::_Useless>::type) [with _Functor = A; _Res = void; _ArgTypes = {}; typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>::_Useless>::type = std::function<void()>::_Useless]’
/usr/include/c++/4.7/functional: In instantiation of ‘static void std::_Function_base::_Base_manager<_Functor>::_M_init_functor(std::_Any_data&, _Functor&&, std::false_type) [with _Functor = A; std::false_type = std::integral_constant<bool, false>]’:
/usr/include/c++/4.7/functional:1812:4: required from ‘static void std::_Function_base::_Base_manager<_Functor>::_M_init_functor(std::_Any_data&, _Functor&&) [with _Functor = A]’
/usr/include/c++/4.7/functional:2300:6: required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor, typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>::_Useless>::type) [with _Functor = A; _Res = void; _ArgTypes = {}; typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>::_Useless>::type = std::function<void()>::_Useless]’
prog.cpp:28:20: required from here
/usr/include/c++/4.7/functional:1841:4: error: use of deleted function ‘A::A(A&&)’
prog.cpp:9:5: error: declared here