Consider the following example:
#include
#include
struct A
{
int i;
void operator()()
{
std::cout &
Is it normal that a
const std::functionmay wrap a mutable functor?
Unfortunately, yes. std::function::operator() is unconditionally qualified as const and doesn't care whether or not the wrapped Callable is mutated. Some papers attempted to tackle this issue, but AFAIK nothing concrete was yet decided:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4348.html
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0045r1.pdf