Variadic function: Difference between revisions

Content deleted Content added
remove personal essay
Added C++0x and C# approach
Line 10:
 
In [[PHP]], [http://php.net/functions_arguments variable-length argument lists] are natively supported (without security risk) since version 4; dedicated functions (<TT>func_num_args</TT>, <TT>func_get_arg</TT>, <TT>func_get_args</TT>) allow the programmer to determine the number and values of unspecified arguments.
 
The variadic function feature is going to be present in the upcoming [[C++]] language standard, [[C++0x]]; this feature is called "Variadic templates". This allows to create templates with variable number of template parameters, which can be also used to create a function with variable number of arguments:
 
template<typename T>
void print( const T& t )
{
std::cout << t;
}
 
template< typename T, typename... Args>
void print( const T& t, const Args&... args )
{
print( t );
print( args... );
}
 
The [[C#]] language uses different approach - they just allow that a variable number of arguments of the same type may be passed to a variadic function. Inside the function they are simply collected in an array.
 
==See also==