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 8902219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:33:25+00:00 2026-06-15T01:33:25+00:00

First example: struct State { SomeLargeObjectThatTakesTimeToCopy obj; int x; } myState; auto f =

  • 0

First example:

struct State
{
    SomeLargeObjectThatTakesTimeToCopy obj;
    int x;
} myState;

auto f = [=]() { return myState.x * 2; };

Does the entire myState struct get copied, even though, technically, only the x member is used?

Second example:

struct State
{
    struct SubState
    {
        int x;
    };

    std::vector<SubState> subStates;
} myState;

auto f = [=]() { return myState.subStates[0].x * 2; };

Again, does the entire myState object get copied? If not, then does the entire subStates member get copied?

  • 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-06-15T01:33:26+00:00Added an answer on June 15, 2026 at 1:33 am

    Assuming myState is a local variable (defined in the body of a function), myState would get captured; lambda can only capture whole variables, not bits and pieces.

    If you take your examples as-is, nothing gets captured; lambdas can’t capture global variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example first: template <class HashingSolution> struct State : public HashingSolution { void Update(int idx,
Consider this example: struct { int num; } s, *ps; s.num = 0; ps
I have a Code example here. struct node { int data; struct node *link;
Coding in C: typedef struct { char *string; int one; int two; } Example;
I have some example data: public struct Task { public int INT; public string
Take this structure for example: struct Packing { int x; // 4-byte align int
The first example that take A by value does two moves and the one
First, a tiny example that demonstrates the problem: struct Bar { enum Baz {aa,
When attempting to run the first example in the boost::mpi tutorial , I was
Assume methods M1 and M2 have strongly related responsibilities First example: If • M1

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.