Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6576073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:27:58+00:00 2026-05-25T15:27:58+00:00

I was wondering about the new C++11 lambda functionality, a wonderful addition in my

  • 0

I was wondering about the new C++11 lambda functionality, a wonderful addition in my humble opinion, but I really don’t get the whole variable capturing part. In short my question comes down to “why did the committee decide for this and did not just use [&] functionality (possibly with a keyword then)?”

At first I thought ‘wow, C++ does it again and gives us even more powerful lambdas, sad of the syntax though’. However, then I tried to think of real, useful cases for this complex lambdas I couldn’t think of any.

First, you obviously need it if you want to mix pass-by-reference and pass-by-value. So then the question is, do we actually need pass-by-value in the lambda construct. What is wrong with creating a temporary inside the lambda body. This is similar if you want a copy of an upper scope variable in the body of a loop, we also don’t write [x] while(...) { ... }. Am I missing something here that makes passing by value really necessary and you cannot fall back on constructing a copy yourself?

So we come to the second part, suppose pass-by-value is not necessary, with the current syntax you can specify which variables you want to capture and which not. Once again I do not see the benefit. The lambda is written in local scope, same as the variable. Why would you need to restrict access to these variables? It’s not an interface, not another context and it shouldn’t even be another programmer. It won’t optimize it for compilers either, because using [&] or mentioning each used variable yourself should come down to the same code.

Now, I do know I don’t grasp C++ to its’ fullest and the people on the committee know better than me. So, which of my arguments are wrong (or what did I miss) and why did they not just decide on using the [&] functionality, preferably with a keyword instead of the current (quite ugly) syntax.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:27:58+00:00Added an answer on May 25, 2026 at 3:27 pm

    You need by-reference for efficiency.

    You need by-value to allow the function object to leave the scope of the local variable which it captures.

    std::function<void()> get_foo (const std::string & bar)
    {
        return [=] () {something with bar;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am quite new to Android, and I am really wondering about is how
I'm new to web development and am just wondering about best practices for java
I'm new to creating installers using Visual Studio, and was wondering about the Global
I was wondering about new trends in cryptography. Which algorithms are new ? Which
I'm wondering about that many new applications, I think most built in WPF, has
I'm new to Flex, and I'm wondering about the best practices when it comes
Hey, I'm new to Grails, and I'm wondering about deployment. Once a .war is
I'm wondering about the standard practice with inner classes (in Java but I suppose
I am fairly new to access and I am wondering about a form. In
Being new to ASP.NET MVC, I've been wondering about the signature of Controller methods.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.