C++ Logo

std-proposals

Advanced search

Re: Using function type suggestion

From: Peter Sommerlad (C++) <"Peter>
Date: Tue, 27 Oct 2020 18:21:34 +0100
You can define aliases for function reference or function pointer types.

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.

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.
>
>
>


-- 
Peter Sommerlad
Better Software: Consulting, Training, Reviews
Modern, Safe & Agile C++
peter.cpp_at_[hidden]
+41 79 432 23 32

Received on 2020-10-27 12:21:40