fork download
  1. #include <boost/range/numeric.hpp>
  2. #include <boost/function_output_iterator.hpp>
  3. #include <functional>
  4. #include <iostream>
  5.  
  6. template <class Container>
  7. auto mybackinsrtr(Container& cont) {
  8. // Throw away the first element
  9. return boost::make_function_output_iterator(
  10. [&cont](auto i) -> void {
  11. static bool first = true;
  12. if (first)
  13. first = false;
  14. else
  15. cont.push_back(i);
  16. });
  17. }
  18.  
  19.  
  20. int main() {
  21. std::vector<int> v { 0, 1, 2, 3 }; // any generic STL container
  22. std::vector<int> result;
  23. boost::adjacent_difference(v, mybackinsrtr(result), std::plus<>{});
  24. for (auto i : result) {
  25. std::cout << i << ", ";
  26. }
  27. std::cout << '\n';
  28. return 0;
  29. }
  30.  
  31.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1, 3, 5,