fork(1) download
  1. #if __cplusplus >= 201103L
  2. #include <utility>
  3. #include <algorithm>
  4. #endif
  5.  
  6.  
  7. #if __cplusplus >= 201103L
  8. template<class RefIt, class JudgedIt, class BinaryPredicate>
  9. bool check_repelled(RefIt first, RefIt last, JudgedIt target, BinaryPredicate p){
  10. return last != std::find_if(first, last, [p, target](i)->bool{ p(i, *target); });
  11. }
  12. #else
  13. template<class RefIt, class JudgedIt, class BinaryPredicate>
  14. bool check_repelled(RefIt first, RefIt last, JudgedIt target, BinaryPredicate p){
  15. for(RefIt i = first; i != last; ++i)
  16. if(p(*i, *target))
  17. return true;
  18. return false;
  19. }
  20. #endif
  21.  
  22. template<class InputIt, class OutputIt, class BinaryPredicate>
  23. OutputIt remove_copy_repelled(InputIt first, InputIt last, OutputIt d_first, BinaryPredicate p){
  24. OutputIt d_end = d_first;
  25. for(; first != last; ++first){
  26. if(!check_repelled(d_first, d_end, first, p))
  27. *d_end++ = *first;
  28. }
  29. return d_end;
  30. }
  31.  
  32. template<class ForwardIt, class BinaryPredicate>
  33. ForwardIt remove_repelled(ForwardIt first, ForwardIt last, BinaryPredicate p){
  34. ForwardIt i, j;
  35. for(i = first; i != last; ++i)
  36. if(check_repelled(first, i, i, p))
  37. break;
  38. if(i == last)
  39. return last;
  40. for(j = i; ++j != last;)
  41. if(!check_repelled(first, i, j, p))
  42. #if __cplusplus >= 201103L
  43. *i++ = std::move(*j);
  44. #else
  45. *i++ = *j;
  46. #endif
  47. return i;
  48. }
  49.  
  50. int main() {
  51. // your code goes here
  52. return 0;
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘bool check_repelled(RefIt, RefIt, JudgedIt, BinaryPredicate)’:
prog.cpp:10:58: error: ‘i’ has not been declared
     return last != std::find_if(first, last, [p, target](i)->bool{ p(i, *target); });
                                                          ^
prog.cpp: In lambda function:
prog.cpp:10:70: error: ‘i’ was not declared in this scope
     return last != std::find_if(first, last, [p, target](i)->bool{ p(i, *target); });
                                                                      ^
prog.cpp:10:83: warning: no return statement in function returning non-void [-Wreturn-type]
     return last != std::find_if(first, last, [p, target](i)->bool{ p(i, *target); });
                                                                                   ^
stdout
Standard output is empty