C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Return type of function available inside function

From: Oleksandr Koval <oleksandr.koval.dev_at_[hidden]>
Date: Tue, 24 Jan 2023 23:29:34 +0200
But you can already use auto return type in the first example.

In:
auto Func2(double a, int b)
{
    return_t obj; // #1
    return a + b; // # 2
}

the compiler can't know the return type at #1 because it becomes clear only
at #2.

On Tue, Jan 24, 2023 at 10:58 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:

> Instead of writing a function as follows:
>
> template<typename T>
> typename T::allocator_type::rebind<typename T::key_type> Func(T &container)
> {
> typename T::allocator_type::rebind<typename T::key_type> obj;
> return obj;
> }
>
> It would be nice, inside the body of the function, to have a simple
> keyword for the function's return type, like this:
>
> template<typename T>
> typename T::allocator_type::rebind<typename T::key_type> Func(T &container)
> {
> return_t obj;
> return obj;
> }
>
> Furthermore this new keyword could be used in functions with 'auto' return
> type:
>
> auto Func2(double a, int b)
> {
> return_t obj;
>
> return a + b;
> }
>
> This could get pretty elaborate where one template function calls
> another, for example:
>
> template<class A, class B>
> auto Func4(A a, B b)
> {
> return_t obj;
>
> return Converter<B,A>::Process(a) + Converter<B,A>::Process(b) +
> SumOf<A,B>(a,b);
> }
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


-- 
Regards,
Oleksandr Koval.

Received on 2023-01-24 21:29:47