Below is excerpted from cppref:
template<class...>
class move_only_function; // not defined
template<class R, class... Args>
class move_only_function<R(Args...) const>;
I also tried the following code:
// ok
std::function<int(int)> fn;
// error: implicit instantiation of undefined template
// 'std::function<void () const>'
std::function<int(int) const> fn;
Is int(int) const
a valid function type in C++23?
Is
int(int) const
a valid function type in C++23?
Yes, int(int) const
has always been(even before c++23) a function type. Even auto(int)const->int
is a function type.
This can be seen from dcl.fct:
- In a declaration T D where D has the form
D1 ( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt noexcept-specifieropt attribute-specifier-seqopt
- In a declaration T D where D has the form
D1 ( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt noexcept-specifieropt attribute-specifier-seqopt trailing-return-type
- A type of either form is a function type.
(emphasis mine)
This means that both are auto(int)const->int
as well as int(int)const
are function type.
using type = int(int) const; //this is a function type
using anothertype = auto(int)const->int; //this is also a function-type