C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::elide

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 23 May 2024 16:36:26 +0100
On Thu, May 23, 2024 at 3:59 PM Jason McKesson wrote:
>
> If the problem is "I can't return arrays", maybe fix *that* instead of
> this hackery. There are plenty of places where someone wants to return
> an array where RVO isn't really the solution.


So if we were to change C++26 in order to allow the following function:

    int Func(void)[3]
    {
        int arr[] = {1,2,3}
        return arr;
    }

Well the only possible pitfall I can see is altering template
instantiation and SFINAE, such as in the following program:

    #include <iostream>

    template<typename R, typename... Params> requires requires {
((R(*)(Params...))nullptr)(); }
    void Func(void)
    {
        std::cout << "Possible\n";
    }

    int main(void)
    {
        Func<int>();
        Func<int[3]>();
    }

But other than where "enable_if" or "requires" is used, I can't think
off-hand of a reason not to allow returning arrays by value.

Received on 2024-05-23 15:36:38