fork(1) download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. class foo
  5. {
  6. public:
  7. void visitWith(const std::function<void(foo&)> &v) { v(*this); }
  8. void visitWith(const std::function<void(const foo&)> &v) const { v(*this); }
  9. };
  10.  
  11. int main()
  12. {
  13. foo f;
  14. f.visitWith([&](foo&){ std::cout << "visited with non-const" << std::endl; });
  15. f.visitWith([&](const foo&){ std::cout << "visited with const" << std::endl; });
  16. return 0;
  17. }
Success #stdin #stdout 0s 4356KB
stdin
Standard input is empty
stdout
visited with non-const
visited with const