Date: Tue, 27 Oct 2020 14:02:43 -0400
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 ?
>
> 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. For any data type I can use the same type alias when declaring
and defining the data type.
>
> Regards
> Peter.
>
> Edward Diener via Std-Proposals wrote on 27.10.20 17:42:
>> C++ has a very good type system for creating types and using them in
>> the same way whether in declarations or definitions. But one area of
>> using types seems less than ideal to me. Let us suppose we create a
>> function type:
>>
>> using my_function_type = int ( long, double, short, char ) ;
>>
>> We can now declare a function using that type, as in:
>>
>> my_function_type my_function ;
>>
>> and this is totally equivalent to:
>>
>> int my_function ( long, double, short, char ) ;
>>
>> but there is no way to use that same type in the definition of the
>> function 'my_function'. Instead we must spell out the type again
>> entirely, adding in the 'my_function' name and the names for the
>> function parameters, as in:
>>
>> int my_function ( long a1, double a2, short a3, char a4 )
>> {
>> // function body using the parameter names and returning an 'int' etc.
>> }
>>
>> Ideally we would like to reuse that function type and just add in the
>> name 'my_function' and the names for the parameters 'a1', 'a2', 'a3',
>> and 'a4' which we use in the function body.
>>
>> Has anybody ever seen this as a limitation of C++, as I do ?
>>
>> I am not proposing a syntax solution but just bringing up this issue,
>> to see if any other C++ programmers regard this as a weakness in the
>> C++ type system that might be remedied by a proposal. I bring this up
>> because I can not think offhand of any other situation where a type in
>> C++ can not be used in the same way both in the declaration and
>> definition of a C++ entity. Perhaps I am not making a necessary
>> distinction between using C++ types with data variables and callables,
>> but if so I would still like to hear other opinions in this matter.
>>
>>
>>
>
>
> 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 ?
>
> 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. For any data type I can use the same type alias when declaring
and defining the data type.
>
> Regards
> Peter.
>
> Edward Diener via Std-Proposals wrote on 27.10.20 17:42:
>> C++ has a very good type system for creating types and using them in
>> the same way whether in declarations or definitions. But one area of
>> using types seems less than ideal to me. Let us suppose we create a
>> function type:
>>
>> using my_function_type = int ( long, double, short, char ) ;
>>
>> We can now declare a function using that type, as in:
>>
>> my_function_type my_function ;
>>
>> and this is totally equivalent to:
>>
>> int my_function ( long, double, short, char ) ;
>>
>> but there is no way to use that same type in the definition of the
>> function 'my_function'. Instead we must spell out the type again
>> entirely, adding in the 'my_function' name and the names for the
>> function parameters, as in:
>>
>> int my_function ( long a1, double a2, short a3, char a4 )
>> {
>> // function body using the parameter names and returning an 'int' etc.
>> }
>>
>> Ideally we would like to reuse that function type and just add in the
>> name 'my_function' and the names for the parameters 'a1', 'a2', 'a3',
>> and 'a4' which we use in the function body.
>>
>> Has anybody ever seen this as a limitation of C++, as I do ?
>>
>> I am not proposing a syntax solution but just bringing up this issue,
>> to see if any other C++ programmers regard this as a weakness in the
>> C++ type system that might be remedied by a proposal. I bring this up
>> because I can not think offhand of any other situation where a type in
>> C++ can not be used in the same way both in the declaration and
>> definition of a C++ entity. Perhaps I am not making a necessary
>> distinction between using C++ types with data variables and callables,
>> but if so I would still like to hear other opinions in this matter.
>>
>>
>>
>
>
Received on 2020-10-27 13:02:52