Consider the following example:
#include <iostream>
#include <functional>
struct A
{
int i;
void operator()()
{
std::cout << ++i;
}
};
void test(std::function<void()> const& fun)
{
fun();
}
int main() {
const std::function<void()> f{A{}};
test(f);
test(f);
}
It const std::functionmay cause no const operator().
Conclusion:
12
The same thing happens if I put a mutablelambda, for example.test([x = 0]() mutable { ++x; });
How can it be?
Is it normal what a const std::functionmutable functor can wrap?
source
share