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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:49:44+00:00 2026-05-26T04:49:44+00:00

Refering to the C++11 specification (5.1.2.13): A lambda-expression appearing in a default argument shall

  • 0

Refering to the C++11 specification (5.1.2.13):

A lambda-expression appearing in a default argument shall not implicitly or explicitly capture any entity.
[ Example:

void f2() {
    int i = 1;
    void g1(int = ([i]{ return i; })()); // ill-formed
    void g2(int = ([i]{ return 0; })()); // ill-formed
    void g3(int = ([=]{ return i; })()); // ill-formed
    void g4(int = ([=]{ return 0; })()); // OK
    void g5(int = ([]{ return sizeof i; })()); // OK
}

—end example ]

However, can we also use a lambda-expression itself as the default value for a function argument?

e.g.

template<typename functor>
void foo(functor const& f = [](int x){ return x; })
{
}
  • 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-26T04:49:45+00:00Added an answer on May 26, 2026 at 4:49 am

    Yes. In this respect lambda expressions are no different from other expressions (like, say, 0). But note that deduction is not used with defaulted parameters. In other words, if you declare

    template<typename T>
    void foo(T = 0);
    

    then foo(0); will call foo<int> but foo() is ill-formed. You’d need to call foo<int>() explicitly. Since in your case you’re using a lambda expression nobody can call foo since the type of the expression (at the site of the default parameter) is unique. However you can do:

    // perhaps hide in a detail namespace or some such
    auto default_parameter = [](int x) { return x; };
    
    template<
        typename Functor = decltype(default_parameter)
    >
    void foo(Functor f = default_parameter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Refering to the example on the Documentation for Gtkmms GdkRGB : #include <gtk/gtk.h> #define
Refering to a previously asked question , I would like to know how to
I am refering to the question on changing the classpath programmatically. I read and
I have tried to do this refering to following link. http://skypher.com/index.php/2008/07/28/function-list-for-php/ But no success.
I am using Server version: Apache/1.3.34 (Debian) mod_perl - 1.29 By refering to STDIN,
I was watching MIX session. Presenter there was refering Panoramic experience in windows phone.
I get this, clicking 'no' means the page displays flawlessly. it's refering to this
I am refering to this article from Jimmy Bogard He is suggesting two projects
i am refering to this question ASSIGN win XP commandline output to variable i
I have a folder named Common/Images/Photounavailable.jpg . Is this right way of refering to

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.