![]() ![]() To answer this question, let us consider a lambda which does not capture any data as shown in Code Listing 1.Īuto lambda = ( const char * callee )Ī lambda that contains move-only variables is only accepted by the following variants: ![]() Why might it be a good idea to pass by value? Std::find_if, for example, is passed by value in all overloads. How Does The STL Do It?Ī look into the STL reveals that in (almost?) all places lambdas are passed by value. Therefore, good old “universal reference” seems to be the more appropriate term in this context. The code examples but only used in place. ![]() * I will be using the term “universal reference” in this blog post and not “forwarding reference” since those references will not be forwarded in There are several ways and it might not be obvious which one is the optimal way: Looking for the best way of how to pass-in lambda functions as a parameter. universal-reference) tempted me to create this post. How To Pass Lambda Functions in C++ (By Value, By L-Value Reference, By Universal Reference)Ī question that I’ve asked on StackOverflow: C++ best practice: Pass use-only (not stored) lambda argument to function by const-reference or byįorwarding-reference (a.k.a. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |