[PATCH] D99560: Utility to construct visitors from lambdas.

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 2 23:49:42 PDT 2021


dblaikie added a comment.

In D99560#2667272 <https://reviews.llvm.org/D99560#2667272>, @ezhulenev wrote:

> `std::forward` with inheritance does not remove a need to invoke a copy constructors, I managed to implement `overloaded` using a struct member and super ugly SFINAE that does properly captures lambdas by reference when lambda is a lvalue, however it still does need to copy when lambda is rvalue: https://godbolt.org/z/dqshPW6h1 (top most example, I just count the number of `HeavyStuff::HeavyStuff(HeavyStuff const&)` copy constructor calls in the generated code). But it does look much worse than inheritance.
>
> Though with `-O3` version with forward and version with struct member generate less code than copying by value.

Making a copy on rvalues would be necessary given the current API design where the visitor is an object - but I'm not sure that's a necessary feature of the API, is it? As opposed to a straight function `visit(lambda1, lambda2, value)` - no need to make copies/keep anything alive because it'll all be alive for the full expression.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99560/new/

https://reviews.llvm.org/D99560



More information about the llvm-commits mailing list