#include <iostream>
#include <functional>
class foo
{
public:
void visitWith(const std::function<void(foo&)> &v) { v(*this); }
void visitWith(const std::function<void(const foo&)> &v) const { v(*this); }
};
int main()
{
foo f;
f.visitWith([&](foo&){ std::cout << "visited with non-const" << std::endl; });
f.visitWith([&](const foo&){ std::cout << "visited with const" << std::endl; });
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCmNsYXNzIGZvbwp7CnB1YmxpYzoKCXZvaWQgdmlzaXRXaXRoKGNvbnN0IHN0ZDo6ZnVuY3Rpb248dm9pZChmb28mKT4gJnYpIHsgdigqdGhpcyk7IH0KCXZvaWQgdmlzaXRXaXRoKGNvbnN0IHN0ZDo6ZnVuY3Rpb248dm9pZChjb25zdCBmb28mKT4gJnYpIGNvbnN0IHsgdigqdGhpcyk7IH0KfTsKCmludCBtYWluKCkKewoJZm9vIGY7CglmLnZpc2l0V2l0aChbJl0oZm9vJil7IHN0ZDo6Y291dCA8PCAidmlzaXRlZCB3aXRoIG5vbi1jb25zdCIgPDwgc3RkOjplbmRsOyB9KTsKCWYudmlzaXRXaXRoKFsmXShjb25zdCBmb28mKXsgc3RkOjpjb3V0IDw8ICJ2aXNpdGVkIHdpdGggY29uc3QiIDw8IHN0ZDo6ZW5kbDsgfSk7CglyZXR1cm4gMDsKfQ==