#Template C++ terminology in English

7 messages · Page 1 of 1 (latest)

topaz fog
#

this thing: (since C++17 due to template template)

#include <cstddef>
#include <vector>

template< template<typename...> typename X1, typename T1, typename T2, size_t v1, size_t v2, typename... Args>
void func(X1<char> p1, T1 p2, T2 p3, size_t p4, size_t p5, Args&&... args)
{

}

template< template<typename...> typename X1, typename T1, typename T2, size_t v1, size_t v2, typename... Args>
class Val
{
    
};

int main()
{
    func<std::vector, int, int, 1,2, char, char, char>({}, 0,0,0,0, 'a', 'a', 'a');
    Val<std::vector, int, int, 1,2, char, char, char> localObj;
}

based on what I assume should be:

The global template function func takes the parameters
 a template template type X1, 
 a template type T1, 
 a template type T2,
 a template size_t value v1,
 a template size_t value t2,
 a variadic template type Args
 
 and takes the arguments
 p1 which is of the type X1 with the template types char,
 p2 which is of the type T1,
 p3 which is of the type T2,
 p4 which is of the type size_t,
 p5 which is of the type size_t,
 args which is of the type a variadic argument pack of rvalue references to the type Args
 
The global template class Val is declared with the template types
a template template type X1, 
 a template type T1, 
 a template type T2,
 a template size_t value v1,
 a template size_t value t2,
 a variadic template type Args
 

is my terminology correct?

royal flickerBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

unkempt glen
#

I would say
The global function template func takes the template parameters

  • a template X1 taking an arbitrary number of types as arguments,
  • a type T1
  • a type T2
  • a size_t v1 (so a non-type template parameter)
  • a size_t v2
  • a (template) parameter pack Args... of types
    An instantiation of that templated function takes the parameters
  • p1, which is of the type X1<char>, so the template parameter X1 instantiated with char
  • p2, of type T1
  • p3 of type T2
  • p4 of type size_t
  • p5 of type size_t
  • a (function) parameter pack args..., which consists of forwarding references to Args...
    The global class template Val takes the template parameters
  • a template X1 taking an arbitrary number of types as arguments,
  • a type T1,
  • a type T2,
  • a size_t v1
  • a size_t v2
  • Args..., a pack of types
    Because both of these templates take a pack, they are variadic templates.
#

There's no such thing as a template function, you have a function template. Every function template gives you a templated function (but e.g. a member function of a templated class would also be a templated function, but not a function template)

#

A parameter is what you say that a function or template takes, an argument is what you call / instantiate it with. So e.g. void foo(int x) has a parameter x, and if you write foo(42) then the argument is 42

#

And it's important to note that Args&&... args are not rvalue references, they're forwarding (aka universal) references

topaz fog
#

bump