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. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1 2 3 4 5 1 1 1