#include <iostream>
#include <type_traits>
void func()
{
}
int main()
{
using T = const decltype(func) &;
using T2 = void (&)();
std::cout << std::boolalpha << std::is_same_v<T, T2> << std::endl;
}
How do you declare a const reference
to a function type? The statement above prints true
so I'm assuming that the const
in T
is ignored somehow. Is it possible at all to declare a const reference
to a function type?
[dcl.fct]p7:
The effect of a cv-qualifier-seq in a function declarator is not the same as adding cv-qualification on top of the function type. In the latter case, the cv-qualifiers are ignored.
So you can only have a reference to a function, but not a const&
as the const
on a function type is ignored, as per above.
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