C++ Logo

std-proposals

Advanced search

Re: Using function type suggestion

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 27 Oct 2020 14:06:02 -0400
On Tue, Oct 27, 2020 at 2:03 PM Edward Diener via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On 10/27/2020 1:21 PM, Peter Sommerlad (C++) via Std-Proposals wrote:
> > You can define aliases for function reference or function pointer types.
>
> What do you mean by a type alias for function reference as opposed to a
> type alias for a function type ?

He means this:

```
using function_ref = int(&)(long, double, short, char);
```

`function_ref` is a reference to a function. You can use it to declare
reference variables to functions of that type.

>
> >
> > Why would you like to have an alias for a function type. Functions are
> > neither objects nor references.
> >
> > You might be aware that template arguments can be formed from such
> > "degenerated" function types (see std::function template arguments for
> > example)
> >
> > So what is the problem you are intending to solve by your suggestion?
> >
> > IDEs tend to be quite good at keeping function signatures in sync.
>
> If I can declare a function using a type alias I think I should be able
> to specify the function signature using the same alias when defining the
> function.

That doesn't answer the question: why do you *need* to do this?

Equally importantly, you're going to have to type the parameter names
again in order to use them in the function definition. So what's the
point?

> For any data type I can use the same type alias when declaring
> and defining the data type.

Functions aren't data (object) types.

Received on 2020-10-27 13:06:32