Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Foo
- {
- Foo(){}
- void Func(){}
- };
- int main()
- {
- const Foo foo;
- [foo]() mutable { foo.Func(); };
- }
- testcase.cpp: In lambda function:
- testcase.cpp:10:29: error: no matching function for call to ‘Foo::Func() const’
- testcase.cpp:10:29: note: candidate is:
- testcase.cpp:4:7: note: void Foo::Func() <near match>
- testcase.cpp:4:7: note: no known conversion for implicit ‘this’ parameter from ‘const Foo*’ to ‘Foo*’
- testcase.cpp:10:20: error: member function 'Func' not viable: 'this' argument has type 'const Foo', but function is not marked const
- std::async([foo]() mutable { foo.Func(); });
- struct S
- {
- void f();
- void fc() const;
- };
- void g()
- {
- S s0;
- // [s0] () { s0.f(); }; // error, operator() is const
- [s0] () { s0.fc(); }; // OK, operator() is const, S::fc is const
- [s0] () mutable { s0.f(); };
- [s0] () mutable { s0.fc(); };
- const S s1;
- // [s1] () { s1.f(); }; // error, s1 is const, no matter if operator() is const
- [s1] () { s1.fc(); };
- // [s1] () mutable { s1.f(); }; // error, s1 is const, no matter if operator() is const
- [s1] () mutable { s1.fc(); };
- }
- struct Foo
- {
- Foo(){}
- void Func(){}
- };
- int main()
- {
- const Foo foo;
- {
- Foo& fooo= const_cast<Foo&>(foo);
- [fooo]() mutable { fooo.Func(); };
- }
- }
- struct Foo
- {
- Foo(){}
- void Func(){}
- };
- int main()
- {
- const Foo foo;
- [foo = foo]() mutable { foo.Func(); };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement