Simple question about lambda expressions

What's the difference between:

1
2
3
auto a = []() { };

const auto b = []() { };


Thanks in advance to anyone who replies!
Last edited on
In exactly this situation there is no difference (aside from that type of second lambda is const /*unspecified*/, but it won't change anything)

However if second lambda was capturing mutable one, it would be uncallable:

1
2
3
4
5
6
7
8
int main()
{
    int i = 0;
    auto a = [=]() mutable { ++i; };
    const auto b = [=]  () mutable { ++i; };
    a(); //Works fine
    b(); //Error, operator() is non-const
}
Last edited on
Topic archived. No new replies allowed.