std::bind(): bind lambda with rvalue reference as argument

不问归期 提交于 2019-12-04 19:26:00

The specification for std::bind is rather dense. In brief, a plain bound argument (not a bind expression, not a reference_wrapper, and not a placeholder) is passed to the bound function as std::forward<Vi>(tid) where Vi is TiD cv &, cv is the cv-qualifiers of the call wrapper, TiD is the type decay_t<Ti>, Ti is the type actually passed to bind, and tid is "an lvalue of type TiD constructed from std::forward<Ti>(ti)", and ti is the argument passed to bind.

Applying this to your call, we see that Ti is Dog and ti is Dog("DogABC"). So TiD is also Dog, and Vi is cv Dog &, which means that std::forward<Vi>(Tid) is an lvalue, and the compiler complains because your lambda takes an rvalue reference parameter, and an rvalue reference parameter cannot bind to a lvalue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!