TartanLlama / function_ref

A lightweight, non-owning reference to a callable.
Creative Commons Zero v1.0 Universal
169 stars 23 forks source link

Update README.md #6

Closed mortenvp closed 5 years ago

mortenvp commented 5 years ago

I think the previous version of the README.md has a dangling reference to the lambda.

mortenvp commented 5 years ago

If I understand the fix in #5 correctly the readme also contains a dangling reference to a lambda.

TartanLlama commented 5 years ago

Nah, that's fine. The fixes to the tests were needed because of this:

tl::function_ref<void(void)> ref = 
  []{} //this is an rvalue, so it will cease to exist after the semicolon
  ; //now ref dangles
ref(); //BOOM

But passing a lambda directly to a function_ref parameter is fine, because:

void f(tl::function_ref<void(void)>);

f(
  []{} //this is an rvalue, so it will cease to exist after the semicolon
  ); //now the closure is dead, but since we only use it in `f`, it's all good

Of course if f stored the function_ref somewhere it'd be a different story.

Does that make sense?

mortenvp commented 5 years ago

Makes sense :+1: