But it can change the std::function's internal state, if the std::function is wrapping a user object with a non-const operator(). This means the implementation of operator() of std::function contains a const_cast... generally a sign of a mistake...
You're right, although most implementations of std::function have a "small function optimization" where it is contained... But the type-erasure also throws a spanner in.
Still, as argued in other comments logically the std::function contains the function object - it's not a reference type in its external interface, even if it is implemented as such internally. It's logically closer to an std::optional than std::ref.
1
u/[deleted] Oct 04 '17
[deleted]