Cheapest way of binding local variable to closure

Posted by mmotorny on Stack Overflow See other posts from Stack Overflow or by mmotorny
Published on 2012-04-07T11:19:48Z Indexed on 2012/04/07 11:29 UTC
Read the original article Hit count: 247

Filed under:
|

I believe following to be a cheapest way of binding local variable to closure:

void ByRValueReference(A&& a) {
}

std::function<void ()> CreateClosureByRValueReference() {
  A a;
  std::function<void ()> f = std::bind(&ByRValueReference, std::move(a)); // !!!
  return f;
}

However, it does not compile under Clang 3.1:

error: no viable conversion from '__bind<void (*)(A &&), A>' to 'std::function<void ()>'

and gcc 4.6.1:

/usr/include/c++/4.6/functional:1778:2: error: no match for call to ‘(std::_Bind<void (*(A))(A&&)>) ()’

Am I violating the standard or it's just broken standard libraries?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c++11