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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:32:56+00:00 2026-05-20T05:32:56+00:00

I want get the type of lambda as the template argument. How to do

  • 0

I want get the type of lambda as the template argument. How to do this?

template<class T>
class Foo
{
public:
    Foo(T t){ t(); }
};

int main()
{   
    Foo< type?? > foo([](){ cout<<"construct OK"; });

    system("pause");
    return 0;
}
  • 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-20T05:32:57+00:00Added an answer on May 20, 2026 at 5:32 am

    It’s possible to deduce the type of a lambda-expression when it is the argument to a function template function parameter whose type is deduced.

    Lambda expressions however are explicitly forbidden to appear inside an unevaluated operand — this includes decltype. It was found that this includes several yet unhandled special cases and it was found that there is no real utility to allow lambda expressions inside decltype and friends. Recall that every lambda expression creates a new unique type.

    You can instead use std::function<void()>, which is able to store any function object that can be called without arguments and yields void as return type.

    Foo< std::function<void()> > foo([](){ cout<<"construct OK"; });
    

    Of course, as I said above, function templates can deduce their argument type, so you can also make the constructor a template

    class Foo
    {
    public:
        template<typename T>
        Foo(T t){ t(); }
    };
    
    Foo foo([](){ cout<<"construct OK"; });
    

    But I take it that this is not really useful in your case, since you presumably want to do something with T inside your class definition. Like, storing the object as a non-static data member. With std::function, that’s possible.

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

Sidebar

Related Questions

I want to get table metadata for all table columns. Like type string(varchar2)/int/float/datetime and
I got this url /search/renttype-all.place-all.type-all.bedrooms-all.0.0/ I want to get the text after the second
Ok, this is what I want to do: public static void CallStaticMethod(Type myType, String
I want to get type of TKey and TValue given a Dictionary<TKey,TValue> type. eg.
I want to get the type of file uploaded using the ASP.NET FileUpload control.
I want to get a MIME Content-Type from a given extension (preferably without accessing
What I want to do is take any class type and create a list
I'm trying to create a UniqueAttribute using the System.ComponentModel.DataAnnotations.ValidationAttribute I want this to be
Suppose I have a class: class MyClass { public int MyMethod(Func<int, int> f) {
We can use a C# typeof keyword when we want to get Type instance

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.