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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:15:07+00:00 2026-06-17T17:15:07+00:00

Is there a tricky way to prevent an object from being captured by reference

  • 0

Is there a tricky way to prevent an object from being captured by reference into a lamba? For example, I’d like to disallow this:

class A {};

void Foo()
{
    A a;
    auto lamda = [&a](){};      // Disallow this
    // give lambda to async process
    // use A to help know when the lamda finally gets called
}

I want to prevent this because A could be easily misused in this context, so I’d like to prevent the user from harming themselves. One could argue that any class can be misused, but given A‘s contract it is really tempting for a user to do this. I have the freedom to wrap, change, and otherwise obfuscate A as much as needed.


Edit

After the lambda is created it is handed off to an asynchronous process while the current thread waits inline until that asynchronous process has completed. A is a class to help know when the async operation completes (think boost::future).

  • 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-17T17:15:08+00:00Added an answer on June 17, 2026 at 5:15 pm

    You can’t do that. Any lvalue of type T can bind to a variable of type T &. You can’t prevent an object from being the value of an lvalue expression (e.g. an id-expression).

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

Sidebar

Related Questions

Is there any tricky way to format seconds like hours:minutes:seconds. For example, 3660 seconds
I was wondering if they was a way to prevent some commands from being
Is there any tricky way to implement a set data structure (a collection of
Should I merge those tables into one table? Is there any tricky alternative? Table
This is kind of tricky. There is this webpage which, I am guessing, uses
So, this one seems to be a little tricky. There's an image map with
Is there a way to prevent recycling of item rendered with Spark components on
Is there a way to detect what prevents an app from running in a
Is there any tricky way to use Java reserved words as variable, method, class,
I'm having a tricky MSBuild issue. There is a solution file containing multiple web

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.