Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Intelligent suggestions for perfect forwarding

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
awishnick Posted - May 16 2012 : 11:39:54 PM
C++11 has some new functions that use perfect forwarding. The most common example that comes up for me is make_shared. Here's an example:


class MyClass {
    MyClass(int a, char b, float c);
    explicit MyClass(short s);
};
auto p = std::make_shared<MyClass>(2, 'h', 5.0f);


When I type "std::make_shared<MyClass>", I would really like to see autocomplete for the MyClass constructors. In other words, when I type "make_shared<MyClass>(", I would like it to behave as if I had typed "new MyClass(".

Instead, once I type the opening parentheses, I see code completion for the make_shared function, which looks something like (since VS doesn't support variadic templates yet):


template <class Type>
shared_ptr<Type> make_shared();
template <class Type, class A1>
shared_ptr<Type> make_shared(A1&& a1);
template <class Type, class A1, class A2>
shared_ptr<Type> make_shared(A1&& a1, A2&& a2);


I know in general it isn't really possible to inspect a function that does perfect forwarding and determine what's being done. Maybe there are more sophisticated things that could be done, but I think it would be extremely useful to allow the user to specify that a function has these semantics. In other words, have a list of functions in some configuration, containing make_shared by default. If this is a function template, with the first template argument as a class, explicitly specified, and the rest as rvalue reference parameters, show autocompletion for constructors of the class that is the first template argument. In other words, show the constructors of MyClass in my example.

So, if the user types "function_name<SomeClass>(", and function_name is in that list, autocomplete would show results for constructors of SomeClass.

Thanks for your time!
5   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Mar 08 2017 : 1:58:25 PM
Thank you for your interest and explanation, knowing who is interested in what helps us to prioritise the order in which we do things. I have added a note to the case about your interest in this, but unfortunately I cannot yet give you an estimate for if or when this will be done.
burbelgruff Posted - Mar 08 2017 : 08:36:07 AM
This is now more relevant than ever. Whenever you have a function
template<typename... Args>
void ForwardingFunction(Args...&& args)
{
return MyForwardedCall(std::forward<Args>(args)...);
}

or, as is the case for std::make_shared:
template<typename T, typename... Args>
T make_shared(Args...&& args)
{
//Simplified
T* value = new T(std::forward<Args>(args)...);
return value;
}

we want to also forward autocompletion. This scenario is increasingly common, and a solution to this would greatly improve productivity.
feline Posted - May 25 2012 : 1:15:47 PM
Thank you for the update, I have put in a feature request to special case support for make_shared to see what our developers make of it:

case=66895
awishnick Posted - May 23 2012 : 2:33:03 PM
I don't have a lot of functions that do this. I can imagine that it's way easier to special-case this for make_shared than to support this in general. I think it would be great to have general support, but special casing make_shared would be extremely useful on its own, and probably cover 90% of the cases I run into.

Thanks!
feline Posted - May 21 2012 : 4:28:57 PM
Do you have a lot of functions that do this? Or would trying to add some form of special case handling for std::make_shared be enough for now?

As soon as you get into multiple parameters to the template, I suspect we are going to hit a massive pile of edge cases here, and that is before we start thinking about people wrapping this in macro's.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000