#Templated functions that accept a number of args
12 messages · Page 1 of 1 (latest)
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.
variadic template parameters
e.g. ```cpp
template<typename... Args>
void f(Args... args);
Args can be a pack of any number of types
hi kolio98
... and the raw debugger can show you all the existing template instantiations in your program by politely asking info functions f
For example, since C# doesn't have this feature, they do functions like this:
Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,TResult> Delegate
which is naive,
but C++ does:
template< class R, class... Args >
class function<R(Args...)>;
this
this might be beyond their understanding, which is why I made a very simple example
to view the raw templates here @high cape you can use:
template<typename... Args>
void f(Args... args)
{
int num1 = 20;
}
int main()
{
f(1, 4.5, "text", 0.0f, &main);
}
which shows:
<source>: In instantiation of 'void f(Args ...) [with Args = {int, double, const char*, float, int (*)()}]':
<source>:10:6: required from here
10 | f(1, 4.5, "text", 0.0f, &main);
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:5:9: error: unused variable 'num1' [-Werror=unused-variable]
5 | int num1 = 20;
| ^~~~
cc1plus: all warnings being treated as errors
Compiler returned: 1
and here the compiler warning shows the template types instantiated inside the function f