fork download
  1. #include <functional>
  2.  
  3. class my_class {
  4. my_class(const my_class&) = delete;
  5. my_class& operator =(const my_class&) = delete;
  6. public:
  7. my_class() {
  8. }
  9.  
  10. my_class(my_class&&) {
  11. }
  12.  
  13. my_class& operator =(my_class&&) {
  14. return *this;
  15. }
  16.  
  17. void f() const {
  18. }
  19. };
  20.  
  21. int main() {
  22. my_class c;
  23. auto a = [c = std::move(c)]() {c.f();};
  24. std::function<void()> e(std::move(a));
  25. }
  26.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from prog.cpp:1:0:
/usr/include/c++/4.8/functional: In instantiation of ‘static void std::_Function_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::false_type) [with _Functor = main()::__lambda0; std::false_type = std::integral_constant<bool, false>]’:
/usr/include/c++/4.8/functional:1946:51:   required from ‘static bool std::_Function_base::_Base_manager<_Functor>::_M_manager(std::_Any_data&, const std::_Any_data&, std::_Manager_operation) [with _Functor = main()::__lambda0]’
/usr/include/c++/4.8/functional:2457:19:   required from ‘std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = main()::__lambda0; <template-parameter-2-2> = void; _Res = void; _ArgTypes = {}]’
prog.cpp:24:41:   required from here
/usr/include/c++/4.8/functional:1910:34: error: use of deleted function ‘main()::__lambda0::<lambda>(const main()::__lambda0&)’
    __dest._M_access<_Functor*>() =
                                  ^
prog.cpp:23:31: note: ‘main()::__lambda0::<lambda>(const main()::__lambda0&)’ is implicitly deleted because the default definition would be ill-formed:
     auto a = [c = std::move(c)]() {c.f();};
                               ^
prog.cpp:4:5: error: ‘my_class::my_class(const my_class&)’ is private
     my_class(const my_class&) = delete;
     ^
prog.cpp:23:31: error: within this context
     auto a = [c = std::move(c)]() {c.f();};
                               ^
prog.cpp:23:31: error: use of deleted function ‘my_class::my_class(const my_class&)’
prog.cpp:4:5: error: declared here
     my_class(const my_class&) = delete;
     ^
stdout
Standard output is empty