fork download
  1. // g++ -std=c++14 -pedantic -pthread main.cpp
  2. // output: 1 2 3 4 5 1 1 1
  3. #include <algorithm>
  4. #include <vector>
  5. #include <functional>
  6. #include <iterator>
  7. #include <iostream>
  8.  
  9. int main()
  10. {
  11. std::vector<int> a = { 1, 2, 3, 2, 4, 5, 1, 1, 3, 5, 1, 5 }, b = { 2, 5, 5, 3 }, c;
  12.  
  13. std::copy_if(a.begin(), a.end(), std::back_inserter(c),
  14. std::bind(std::less<>(), // this won't work in pre-C++14
  15. std::bind(
  16. std::count<std::vector<int>::iterator, int>,
  17. std::bind(static_cast<std::vector<int>::iterator (std::vector<int>::*)()>(&std::vector<int>::begin), &c),
  18. std::bind(static_cast<std::vector<int>::iterator (std::vector<int>::*)()>(&std::vector<int>::end), &c),
  19. std::placeholders::_1
  20. ),
  21. std::bind(
  22. std::minus<>(), // this won't work in pre-C++14
  23. std::bind(
  24. std::count<std::vector<int>::iterator, int>,
  25. a.begin(),
  26. a.end(),
  27. std::placeholders::_1
  28. ),
  29. std::bind(
  30. std::count<std::vector<int>::iterator, int>,
  31. b.begin(),
  32. b.end(),
  33. std::placeholders::_1
  34. )
  35. )
  36. )
  37. );
  38.  
  39. std::copy(c.begin(), c.end(), std::ostream_iterator<int>(std::cout, " "));
  40. std::cout << std::endl;
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:11: error: braces around initializer for non-aggregate type 'std::vector<int, std::allocator<int> >'
prog.cpp:11: error: braces around initializer for non-aggregate type 'std::vector<int, std::allocator<int> >'
prog.cpp:13: error: 'copy_if' is not a member of 'std'
prog.cpp:14: error: 'bind' is not a member of 'std'
prog.cpp:14: error: wrong number of template arguments (0, should be 1)
/usr/include/c++/4.3/bits/stl_function.h:226: error: provided for 'template<class _Tp> struct std::less'
prog.cpp:15: error: 'bind' is not a member of 'std'
prog.cpp:17: error: 'bind' is not a member of 'std'
prog.cpp:18: error: 'bind' is not a member of 'std'
prog.cpp:19: error: 'std::placeholders' has not been declared
prog.cpp:21: error: 'bind' is not a member of 'std'
prog.cpp:22: error: wrong number of template arguments (0, should be 1)
/usr/include/c++/4.3/bits/stl_function.h:146: error: provided for 'template<class _Tp> struct std::minus'
prog.cpp:23: error: 'bind' is not a member of 'std'
prog.cpp:27: error: 'std::placeholders' has not been declared
prog.cpp:29: error: 'bind' is not a member of 'std'
prog.cpp:33: error: 'std::placeholders' has not been declared
stdout
Standard output is empty