fork download
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iterator>
  4. #include <iostream>
  5.  
  6. int main() {
  7. std::vector<int> values{1, 2, 3, 4, 5, 6};
  8. int start = 2;
  9. std::copy_if(values.cbegin(),
  10. values.cend(),
  11. std::ostream_iterator<int>(std::cout, " "),
  12. [](const int val) { return val != start; });
  13.  
  14. return 0;
  15. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In lambda function:
prog.cpp:12:37: error: 'start' is not captured
   [](const int val) { return val != start; });
                                     ^
prog.cpp:12:4: note: the lambda has no capture-default
   [](const int val) { return val != start; });
    ^
prog.cpp:8:6: note: 'int start' declared here
  int start = 2;
      ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from prog.cpp:1:
/usr/include/c++/5/bits/stl_algo.h: In instantiation of '_OIter std::copy_if(_IIter, _IIter, _OIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _OIter = std::ostream_iterator<int>; _Predicate = main()::<lambda(int)>]':
prog.cpp:12:45:   required from here
/usr/include/c++/5/bits/stl_algo.h:746:12: error: could not convert '__pred.main()::<lambda(int)>(((int)__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<const int*, std::vector<int> >()))' from 'void' to 'bool'
  if (__pred(*__first))
            ^
stdout
Standard output is empty