4
int i = 9;
struct_variable.f = [i](T struct_variable&) {
do_something_with_capture_variable(i);
...
struct_variable.f = another_compatible_std_function;
//do something else, but never use captured variable after here
...
};
struct_variable.f(struct_variable);
호출 동안 :: 함수 성병 및 콜백에서 struct_variable.f
캡처 변수를 사용하여 마무리 후 another_compatible_std_function
로 대체된다.할당 새로운 값 람다 함수 (도 <code>std::function</code>를 입력 함) 부재 <code>struct_variable.f</code>로 저장
이 방법이 안전하다는 보장이 있습니까?
회원님의 멤버 함수 중 하나를 실행하는 동안 상황을 '삭제'하는 것과 비슷하기 때문에 신중할 때까지 '예'라고 말하고 싶습니다. 그러나 이것은 표준에서 증명하기가 어렵습니다. – aschepler