In other words when function declared like this with 'T' being some type-alias:
T (...)
will be ever useful?
If you don't know such declaration specifies a function with unknown number of parameters. It's allowed by the C++ standard but it doesn't provide us with a standard way of accessing passed arguments. There is <cstdarg>
library but it require named parameter before the ellipsis in order to work. It look like this (with another type-alias named 'T1'):
T (T1, ...)
Normally T1
is of type int
and sepcifies the number of variadic arguments.
However the fact that the ellipsis can be the only function parameter means that such construct have some purpose and I'm curios what is it?
An actual example of such function will look like this:
void func(...)
{
}
One example is the metaprogramming trick to take advantage of the fact that ...
is always a viable overload but is the least preferred. For example, this type trait checks if a particular member (foo
) exists:
template <typename T>
struct has_foo {
template <typename U>
static std::true_type test( decltype(U::foo)* );
template <typename U>
static std::false_type test( ... );
using type = decltype(test<T>(0));
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With