Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Variadic template parameter info

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
hophop Posted - Feb 11 2018 : 03:41:03 AM
Hey,

I know its difficult, but sometimes (often), the type of parameters are restricted by the code of the function.
Lets take an example. In vs2017 make_unique looks like that :

template<class _Ty, class... _Types, enable_if_t<!is_array_v<_Ty>, int> = 0>
inline unique_ptr<_Ty> make_unique(_Types&&... _Args)
{
// make a unique_ptr
return (unique_ptr<_Ty>(new _Ty(_STD forward<_Types>(_Args)...)));
}


So the parameters are actually restricted to the parameters of each version of the constructor.
I know there are cases that are much more complex. And sometimes its not even possible to deduce anything.
C++ 20 concepts might as well help constraining some stuff, but the two dont overlap.

There should be a way to run an analysis over the function's AST and deduce the parameters, more often than not.

That kind of feature would be a huge step forward in helping c++ be more user friendly i think.
7   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Feb 16 2018 : 08:58:41 AM
I have put in a feature request for this, starting with the "make_unique" case, since this is a fairly common function call, and the information we are after is clear and well defined:

case=114529
hophop Posted - Feb 16 2018 : 07:50:22 AM
quote:
since we don't know which member functions the template is going to check


I'm not sure what you mean here. make_unique is a function, not a class.
The case of classes is a bit different, cause template arguments have to be well defined in the type, at variable declaration. Thus, it works as expected.(see below)




The issue arises when variadic template are deduced from the passed parameters, in a template function.

quote:
plus any templates is also calls... Which is why I am wary about this.

This is true though. I can get that.
But then it can be dealt with recursively. Or if its too complex you can as well just let it go, and stick with "Args&&... args" (if, lets say, recursion depth is greater than 3, or for more complex cases).
Sorry I dont really want to write an implementation here, I will let it to your engineers.

Code helper tools are not perfect by any means. They are just good enough for what we usually use them for. There is A LOT of bugs, and features that could be improved, because they are too complex to implement, or because of realtime requirements.

The question is, is it worth it? I think good enough results can be achieved with a reasonable amount of work. But that is up to you in the end.
feline Posted - Feb 14 2018 : 10:49:51 AM
VA View first, since what you are seeing is unexpected. I have set up the following simple test case here, using VS2015 and VA 2248. In the header file I have the deeply complex class:

class felineTestConstructorOverloads
{
public:
	felineTestConstructorOverloads(long nSizeOne, long nSizeTwo, long nSizeThree);
	felineTestConstructorOverloads(char *pszName, long nSizeOne, long nSizeTwo, long nSizeThree);
	int getVolume();
};

and I am using it in the cpp file via:
void testingTemplateTypeParameters()
{
	std::unique_ptr<felineTestConstructorOverloads> uniqueFelineTest =
                std::make_unique<felineTestConstructorOverloads>();
}

this does not compile, which is where we started, and shows the problem nice and clearly.

For the HCB though, VA is always updating VA View when I hover the mouse over either instance of "felineTestConstructorOverloads" in the cpp file. I have just double checked this. Now, yes, it can take VA View a second or three to react, but you don't want it updating every time you move the mouse pointer across your code. If you have a case where VA View will never respond to the type under the mouse cursor in the editor this is an interesting problem, and may suggest a deeper problem with VA's understanding of your code.

As for providing information on the "make_unique" call, it depends on how general or specific we are trying to be here.

Saying "make_unique" is a special case function, and gets special case handling to show the constructor parameters of the template type is a well defined feature request. It is also rather narrow. But if we wanted to make this more general then we run into all sorts of problems with defining what we are actually asking VA to do here.

My reading of your posts so far is that you are looking for a more general solution, which is fine. But I am trying to work out how to approach a more general solution, since we don't know which member functions the template is going to check without parsing the the template, plus any templates is also calls... Which is why I am wary about this.
hophop Posted - Feb 14 2018 : 04:41:38 AM
quote:
So you are not really asking about the parameters of the template class, you are after information on the type you are using with the template, in this case your class "A"?


Yes !

Im aware of VA view. But that seems a bit overkill. And there are issues with VA view. eg. : there is a delay for the HCB to update, and sometimes it just doesn't react. If you put the cursor in the template parameter of make_unique, HCB doesnt update (maybe cause its a function?).

I think VA view is just not well suited for this. The parameter info tooltip is way more convenient, it is instantaneous, appears right in front of your eyes, you dont have to move the cursor, etc.

quote:
For other template classes though, the restriction might not be on the constructor. Or there might be more than one restriction.

Yes I agree.

quote:
Trying to summarise all of this in a tooltip could well run away with us, but here VA View should help quite a bit, so long as you have some idea of what the template type is doing with the type it "contains".

You dont have to summarise all of it in the tooltip. One option would be to keep "_Types&&... _Args", but add the constructor parameter types like an overloaded signature (much like a classical constructor).
We do know what make_unique do, what we dont is remember the exact signature of the constructor. The example above is quite simple, but often class are in other files, which might be closed, and you have to guess the arguments.

Besides, one problem remains. The syntax error in case of wrong parameters.

The reason I ask for that is that this should be pretty straight forward to implement.

All you have to do is check the template function/class, and walk the AST to see where the variadic template is expanded. If its in a function call, add the signature to the parameter info tooltip.

C++ is getting more and more complex every day (C++ 20 is coming), of course we could write c++ with notepad but... What I hope is our extensions can keep up with all those changes. Thats what makes writing c++ fun and easy.
feline Posted - Feb 13 2018 : 4:41:35 PM
So you are not really asking about the parameters of the template class, you are after information on the type you are using with the template, in this case your class "A"?

Are you aware of VA View https://support.wholetomato.com/default.asp?W222

If you show VA View, then place keyboard focus back into the editor, and now hover the mouse over the class type "A", VA will show you the details of this class, specifically its member functions, along with the parameters that they take.

Here, since the template class is going to call the constructor, you are looking for the constructor parameters. For other template classes though, the restriction might not be on the constructor. Or there might be more than one restriction. Trying to summarise all of this in a tooltip could well run away with us, but here VA View should help quite a bit, so long as you have some idea of what the template type is doing with the type it "contains".
hophop Posted - Feb 13 2018 : 10:29:31 AM
hmmm... no.
I'm talking about std::make_unique, not std::unique_ptr.

Let me clean up the code a bit to make it simpler.


template<class T, class... TArgs>
unique_ptr<T> make_unique(TArgs... args)
{
    return unique_ptr<T>(new T(args...));
}


There you go.
When I'm talking about restriction, I'm talking about an implicit one.
You can see that "args..." is used in the constructor of T.
So let's say you have a class like this :


class A
{
public:
    A(int i) {}
    A(int i, float f) {}
};


The only code that will compile is the following, because no other version of the constructor exist.

std::unique_ptr<A> ptr = std::make_unique<A, int>(1);
// or
std::unique_ptr<A> ptr = std::make_unique<A, int, float>(1, 2.3);


Now here is how it appears in visual studio, with the parameter info tooltip. (note that the type of the parameters is automatically deduced)



As you can see, with make_unique you dont get the errors, and you dont get any help for the types of the parameters.

This use of variadic template is widely used, its not just specific to make_unique.
More than that, if you dont realize and you try to compile, the compilation error points to the code of make_unique. To find the place you are calling make_unique with wrong arguments, you have to inspect all your code.
feline Posted - Feb 12 2018 : 10:43:41 AM
I am seeing a different definition for std::unique in VS2017, but I think I follow the code correctly.

As I understand it, the parameter type restriction is applied at the template class level, so there is no mention of it at the member function level. So VA isn't going to know about it simply by checking the function.

Are these restrictions found anywhere else? Or are they just at the specific function you are calling and the class declaration? If so, I am thinking that if VA added the template class parameters as a comment to the bottom of the parameter info tooltip that is shown when calling this function, this would give you the information about these restrictions.

Does this make sense, and would this do what you are looking for?

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