template <typename T, typename R, typename ...A>
struct decay<T, R(A..., ...)> { using type = R(*)(A..., ...); };
What's the exact meaning of that? I need some help~
int foo(int);
int bar(int, ...);
these are two different functions. foo
is of type int(int)
. bar
is of type int(int,...)
.
...
is C-style varargs, not to be confused with variardic template arguments which also uses ...
.
template <typename T, typename R, typename ...A>
struct decay<T, R(A..., ...)> { using type = R(*)(A..., ...); };
This part of an implementation of an optimized version of std::decay
within boost::hana
. The typename T
and T
parts are red herrings, part of that optimization.
It is a specialization that matches R(A..., ...)
, where A...
and R
are deduced from a function signature.
If you passed double(int, char, ...)
as the 2nd argument to this hana::details::decay
, R
would be double
and A...
would be int, char
. And the ...
would "match the C-style varags".
This particular specialization's purpose to to map function signatures that end in C-style varargs to pointers to the same signature. So it maps double(int, char, ...)
to double(*)(int, char, ...)
.
C style varargs are not the same as template variardic arguments. They predate it.
This specialization is one of the specializations that enact the decay of a function type to the corresponding pointer-to-function type, which mirrors the way function lvalues decay to function pointer prvalues.
This particular specialization is used for variable-argument functions (those whose parameter list ends in an ellipsis so that it accepts arguments that don't match any parameters).
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