Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 auto insert lambda function parameters
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

joostn
Junior Member

16 Posts

Posted - Mar 13 2015 :  07:26:02 AM  Show Profile  Reply with Quote
Maybe the idea is completely wild, but this would be handy for me:

If I have a function which takes a std::function<> as a parameter:
void f1(std::function< T1<A>(const T2&) > func);

it would be nice if VAX could generate the lambda parameters for me as soon as I begin a lambda function:

f1([


would expand to

f1([](const T2& param1) -> T1<A>{
})

joostn
Junior Member

16 Posts

Posted - Mar 13 2015 :  07:28:44 AM  Show Profile  Reply with Quote
..or maybe not autocomplete the lambda function, but offer it as a smart suggestion when typing f1(
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18751 Posts

Posted - Mar 13 2015 :  4:33:26 PM  Show Profile  Reply with Quote
I need a better idea of what you are thinking here before forming an opinion on this.

Your code samples read like a function declaration and implementation. Yet the implementation, if that is what it is, does not match the declaration. So what is going on here?

I don't really know anything about lambda's yet, it is something I need to read up on. But a quick search for std::function says that this can contain functions, classes or lambda's. So we don't get to just assume that a std::function contains a lambda.

zen is the art of being at one with the two'ness
Go to Top of Page

joostn
Junior Member

16 Posts

Posted - Mar 13 2015 :  5:07:05 PM  Show Profile  Reply with Quote
Here's a more concrete example:

class HttpClient
{
  public:
    void GetWebPage(const std::string &url, std::function<void(const std::string &)> callback);	
};


HttpClient client;
client.GetWebPage("http://www.wholetomato.com/", [](const std::string &result){
  // this gets called asynchronously:
  std::cout << result;
});


Here it's pretty simple, but I'm using templated classes and smart pointers, and spelling out the lambda signature becomes more tedious.

And you're right, the std::function does not necessarily have to be filled by a lambda function but it is a common pattern. So I thought it might be suggested as soon as the [ is typed, or as a smart suggestion after entering the comma.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18751 Posts

Posted - Mar 13 2015 :  8:58:23 PM  Show Profile  Reply with Quote
This example makes the code clearer, but does not help me understand what you are after here. Are you wanting help generating a function implementation, or a function call?

I am not sure how we could help you generate the function call, since how would we know what to use as the parameters?

zen is the art of being at one with the two'ness
Go to Top of Page

joostn
Junior Member

16 Posts

Posted - Mar 14 2015 :  02:15:08 AM  Show Profile  Reply with Quote
The function call. More specifically I would like VAX to generate the second parameter in the GetWebPage function call.

So when I start typing this:
client.GetWebPage("http://www.wholetomato.com/", [

VAX could suggest to expand it to this:
client.GetWebPage("http://www.wholetomato.com/", [](const std::string &){}

The lambda signature can be derived from the std::function<> parameter definition.

Again, the lambda is not the only possible parameter for GetWebPage, I might want to pass a pointer to static function instead, so it should be presented just as a suggestion. But once you start using lambdas this becomes a common pattern.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18751 Posts

Posted - Mar 14 2015 :  8:49:26 PM  Show Profile  Reply with Quote
Having done some reading up on C++ and Lambda functions I can now see what you are talking about, and this does make sense, so I have put in a feature request for this:

case=88468

Thank you for taking the time to explain. I am not sure how likely we are to do this, but it does seem worth considering, especially since we are starting to see more interest in lambda's.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000