Can I use \copydoc with function or template parameters? - c++

In doxygen, there is the \copydoc (or #copydoc) command that allows to copy the documentation text of a link-object, which can point to a:
member (of a class, file or group), a class, a namespace, a group, a page, or a file
That's a nice feature and it works well, but I would like to copy the documentation of a template parameter from another class, but those don't have fully qualified names.
Is there any way to make that possible?

Related

How to check variable type given a clang::VarDecl?

I am writing a clang-tidy check to automate renaming of some variables of a certain type. I can successfully match their declarations with matcher varDecl(hasType(asString("class MyType"))). But then I want to rename these variables and their usages. If I use FixItHint::CreateReplacement(), it only replaces names in the declarations, but not in all usages.
I found a RenamerClangTidyCheck, which seems to be exactly what I need:
/// Base class for clang-tidy checks that want to flag declarations and/or
/// macros for renaming based on customizable criteria.
However, it is customized by overriding virtual functions like getDeclFailureInfo(), which are called from ClangTidyCheck::check() function and they do not have any matchers at hand, they operate with NamedDecl. I am only interested in variables declarations, so I can cast it down to VarDecl, but then how I make sure this particular VarDecl corresponds to a variable with type MyType?

(Can I minimize the) Footprint of template in my C++ Code?

I have a large class which basically handles one buffer of variable (numeric) datatype. So it seems a good choice to use a class template with this datatype as the only parameter. I'm not experienced in C++ and I wonder/worry a bit about the "footprint" such a template makes in my code.
There are three implications of templates which in my (C++ unexperienced) eyes are not necessary and make code ugly. I tried to avoid them, but neither did I find a good example how to do it nor did I manage to find it out by myself.
So the goal of this question is: Can you either confirm the following statements or give a counterexample?
When using a class template, all class methods have to go into the header file. Even if they have no templated type in their interface or implementation.
When using a static method or member of the class, I always have to specify a template parameter (MyClass< double > :: MY_STATIC), even if the templatization does not affect any of the static properties of the class.
When using the class as a parameter for a function, I always have to give a template parameter, even when this function does not access any of the templated members? (function myFunc(MyClass< double> & myClass){ do something } )
As a general rule, don't have functions/data members in a template class which does not use the template parameters. Have a base class, put all non-template related things there, your template class should derive from it.
To answer your questions:
yes, everywhere where you need to instantiate the template, you need to see the full definition of the class and it's functions
yep, but put that into the base class
yes, see above
EDIT: One of the reasons to move to base class is code bloating (this expression actually exist, you can google it for more info): If you don't move the template unrelated code to a base class, the very same template independent code will be copied for all instantiation of your template, which means a lot of unnecessary code. If you put it to a base class, you will only have this code once.
Yes. On the plus side, the code is only generated when the metod is actually used for the specialization.
Yes. However, there is no (other then design choice) need for a static method to be a memeber of the templated class if it has no use for the templated parameter.
Yes. The size and memory layout of the structure is determined by the template parameter.

turning a non-template class into a template

I have a self made data structure (for example linked list) that works well, but when I made the class I did it based around strings, but now I want to take that data structure, and use it to hold another self made data type. I know that this involves templates (the ability to take a working data structure and apply any data type to it), but I have not really worked with them.
what steps should I follow to turn a non-template class into a template class?
The main thing you need to do is put the template specification in front:
template <class T>
class A {
...
};
Then use T instead of using your string type.
There are lots of other things to consider when creating templates, but it depends on the particular situation.
You will specify your new type when you use the template:
A<MyType> my_object;
that is basic actions
Move all method definitions of your class from .cpp to .h file
Put template specifications (template <class T>) before all declarations and definitions
Change all class name specifiers to template names, i.e. A::A(){} should became A<T>::A(){}
If it required, change the names of method calls to ones with type parameters
Change all entries of the previous type to the type parameter name
can be a lot of the other things of course.

passing values between a section template and an other section

i'm using Orbeon section templates in a common library that i use in multiple forms.
I need some values of a given section template to determine the visibility of some controls in other sections of my form. So i'm looking for a solution to parametrize the section template in order to never access its inner control values.
Can someone pls explain to me how to achieve that?
To refer to the value of a field which is inside a section template from a field outside of that section template (and itself not in another section template), you can't use the $field-name syntax. You can from inside the section template, but not from outside the section template. This is because section templates really encapsulate their content, thus allowing you, for instance, to have multiple instances of the same section template in your form, or multiple section templates using the same field names.
So, to answer your question, this is a case where you need to use a path expression. Say the field you want to refer to is named street and you named that particular instance of the template shipping, then you can refer to the value of the field with the expression /form/shipping/street. If you add another instance of that same template, and name that instance billing, then you could refer to that other street field as /form/billing/street.

import all variables of parent class

You may have notice that later versions of gcc is more strict with standards (see this question)
All inherited members of a template class should be called using the full name, ie.
ParentClass<T>::member instead of just member
But still I have a lot of old code that does not respect this. Adding using ParentClass<T>::member for each used member in each class is quite a pain. Is there is a way to do something like using ParentClass<T>::* ?. I would like this better than deactivating this check in g++ but if there is now way, how can I deactivate it ?
Edit:
According to C++ FAQ (thanks sth) these are the only way to correctly solve the inherited member variable names :
Change the call from f() to this->f(). Since this is always implicitly dependent in a template, this->f is dependent and the lookup is therefore deferred until the template is actually instantiated, at which point all base classes are considered.
Insert using B<T>::f; just prior to calling f().
Change the call from f() to B<T>::f().
So now looking for the right switch to deactivate the full name resolution ...
Not really an answer to you question, but you can also write this->member instead of ParentClass<T>::member. This is most often easier to write and makes the compiler look for member in the right places.