Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
visit_union
take the callable by universal reference
Summary: `visit_union` is taking the callable by value, forcing a copy. This is a problem because 1. it's inconsistent with `std::visit`, which instead uses universal references. This results in surprises when using it 2. when the callable returns a coroutine, this guarantees that the coroutine state is destoryed before the coroutine finish execution ``` int a = 0 co_await thrift::visit_union(my_union, [&](auto, auto) -> Task<void> { a += 1; co_return; }); ``` This results in a dangling reference in the old implementation, and it's correct in the new one. This is consistent with the coro wiki: https://www.internalfb.com/wiki/Coro/#lambdas Note: To be consistent the same should probably be done to also `visit_by_thrift_field_metadata` and the other visit functions Triggering problem: https://fb.workplace.com/groups/192968587972839/posts/1656198051649878/?comment_id=1657068398229510&reply_comment_id=1657106148225735 Reviewed By: Mizuchi Differential Revision: D68151611 fbshipit-source-id: a05c53043642b4274dbab63316e6dcb7d21de9f4
- Loading branch information