fork download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <functional>
  4.  
  5. class A {
  6. public:
  7. A(int a = 0): a_(a) {}
  8. A(const A& rhs): a_(rhs.a_) {}
  9. A(A&& rhs) = delete;
  10. void operator() ()
  11. {
  12. std::cout << a_ << std::endl;
  13. }
  14.  
  15. private:
  16. int a_;
  17. };
  18.  
  19. typedef std::function<void()> Function;
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23. std::cout << std::boolalpha;
  24. std::cout << "Copy constructible: "
  25. << std::is_copy_constructible<A>::value << std::endl;
  26. std::cout << "Move constructible: "
  27. << std::is_move_constructible<A>::value << std::endl;
  28. Function f = A();
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty