Post by Bonita MonteroPost by Andrey Tarasevich thread_pool::stop_token stopper( true_type() );
I'd understand that without the "()" the compiler considers
this a declaration, but not with the "()".
Parameters of function type are legal in C++. `true_type()` declares
exactly that.
So, `stopper` is a function that takes a single parameter of type
`true_type()`. The latter is a function with no parameters, returning
`true_type`.
Not true. true_type() is a default-parameter for a unnamed parameter
with not explctitly given name.
Huh??? Not sure what you are trying to say here,... but no.
The parameter is indeed unnamed. But its type is exactly as I stated
above: in this context `true_type()` stands for "a function with no
parameters, returning `true_type`". Parameters of function type are
legal in C++ (and in C), they get immediately _adjusted_ to the
corresponding function-pointer type.
If you give a name to the parameter (say, `x`), your declaration would
become
thread_pool::stop_token stopper( true_type x() );
`x` is a function with no parameters, returning `true_type`. Due to the
aforementioned adjustment this is equivalent to
thread_pool::stop_token stopper( true_type (*x)() );
This is what you declared. End of story.
---
Here's a revealing example for you
struct true_type {};
struct whatever {};
int main()
{
whatever foo(true_type());
void *p = foo;
}
The GCC's error message reads:
error: invalid conversion from 'whatever (*)(true_type (*)())' to 'void*'
https://coliru.stacked-crooked.com/a/a1f11719de8cb94b
See the parameter type?
--
Best regards,
Andrey