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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:36:06+00:00 2026-05-27T11:36:06+00:00

Suppose I have a type my_struct enclosing a member variable, f , which is

  • 0

Suppose I have a type my_struct enclosing a member variable, f, which is a function. It’s possible for f to be a c++11 lambda function.

Since it is illegal to assign to lambda objects, I’d like to implement my_struct‘s assignment operator in such a way that when f is a lambda, it is not assigned.

Is it possible to build a type trait is_lambda which can inspect a type for lambda-ness?

In code:

#include <type_traits>

template<typename Function> struct is_lambda
{
  // what goes here?
};

template<typename Function> struct my_struct
{
  Function f;

  my_struct &do_assign(const my_struct &other, std::true_type)
  {
    // don't assign to f
    return *this;
  }

  my_struct &do_assign(const my_struct &other, std::false_type)
  {
    // do assign to f
    f = other.f;
    return *this;
  }

  my_struct &operator=(const my_struct &other)
  {
    return do_assign(other, typename is_lambda<Function>::type());
  }
};
  • 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-27T11:36:06+00:00Added an answer on May 27, 2026 at 11:36 am

    Impossible without compiler support, as the type of a lambda is just a normal, non-union class type.

    §5.1.2 [expr.prim.lambda] p3

    The type of the lambda-expression (which is also the type of the closure object) is a unique, unnamed nonunion class type […]

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

Sidebar

Related Questions

Suppose I have a variable of type Int = 08, how can I convert
Suppose I have some class which has a property actor_ of type Actor .
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT
Suppose I have a bunch of Clojure data structures, all of the same type
Suppose I have pointer of type ABC* and another pointer of type XYZ* and
Suppose I have an oracle table with two columns: type varchar2 and data varchar2.
Suppose I have some code that looks like this: foreach(type x in list y)
Suppose I want entries in the table Regions to have a type, e.g. a
Suppose you have a trigger on MY_CUSTOMER_TABLE and that it has a variable declared

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.