fork(1) download
  1. #include <functional>
  2. #include <utility>
  3.  
  4. using MyFunction = std::function<int(int)>;
  5.  
  6. struct no_copy
  7. {
  8. no_copy() = default;
  9. no_copy(const no_copy&) = delete;
  10. no_copy(no_copy &&) = default;
  11. };
  12.  
  13. int main() {
  14. no_copy n;
  15. MyFunction f{[n{std::move(n)}] (int i) {(void)n; return i; }};
  16.  
  17. }
  18.  
Compilation error #stdin compilation error #stdout 0s 3452KB
stdin
Standard input is empty
compilation info
In file included from prog.cpp:1:0:
/usr/include/c++/5/functional: In instantiation of 'static void std::_Function_base::_Base_manager<_Functor>::_M_clone(std::_Any_data&, const std::_Any_data&, std::true_type) [with _Functor = main()::<lambda(int)>; std::true_type = std::integral_constant<bool, true>]':
/usr/include/c++/5/functional:1746:16:   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()::<lambda(int)>]'
/usr/include/c++/5/functional:2260:19:   required from 'std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = main()::<lambda(int)>; <template-parameter-2-2> = void; _Res = int; _ArgTypes = {int}]'
prog.cpp:15:63:   required from here
/usr/include/c++/5/functional:1702:4: error: use of deleted function 'main()::<lambda(int)>::<lambda>(const main()::<lambda(int)>&)'
    new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
    ^
prog.cpp:15:32: note: 'main()::<lambda(int)>::<lambda>(const main()::<lambda(int)>&)' is implicitly deleted because the default definition would be ill-formed:
   MyFunction f{[n{std::move(n)}] (int i) {(void)n; return i; }};
                                ^
prog.cpp:15:32: error: use of deleted function 'no_copy::no_copy(const no_copy&)'
prog.cpp:9:2: note: declared here
  no_copy(const no_copy&) = delete;
  ^
stdout
Standard output is empty