fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct hurg {
  6. int x;
  7. };
  8.  
  9. class furg {
  10. public:
  11. template <class F>
  12. void for_each_hurg(F&& f) const {
  13. for (auto& h : hurgs) {
  14. f(h);
  15. }
  16. }
  17.  
  18. /*template <class F>
  19.   void for_each_hurg(F&& f) {
  20.   for (auto& h : hurgs) {
  21.   f(h);
  22.   }
  23.   }*/
  24. template <class F>
  25. void for_each_hurg(F&& f) {
  26. const_cast<const furg&>(*this).for_each_hurg([&f](const hurg& h) {
  27. f(const_cast<hurg&>(h));
  28. });
  29. }
  30.  
  31.  
  32. private:
  33. std::vector<hurg> hurgs;
  34. };
  35.  
  36. int main() {
  37. furg f;
  38. const auto& cf = f;
  39.  
  40. f.for_each_hurg([](hurg& h) { });
  41. cf.for_each_hurg([](const hurg& h) { });
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty