A const std::function wraps a non-const operator() / mutable lambda

前端 未结 1 499
温柔的废话
温柔的废话 2021-01-12 13:12

Consider the following example:

#include 
#include 

struct A
{
    int i;
    void operator()() 
    {
        std::cout &         


        
相关标签:
1条回答
  • 2021-01-12 13:28

    Is it normal that a const std::function may 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

    0 讨论(0)
提交回复
热议问题