Does it work for cases where there are multiple named objects?

std::mutex foo(bool b)
{
    std::mutex m1, m2;
    if (b)
        return m1;
    else
        return m2;
}


Em sex., 11 de ago. de 2023 10:02, Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org> escreveu:
I've written a paper on ensuring the elision of a move/copy operation
when returning a class by value from a function. C++17 already ensures
elision when it comes to Return Value Optimisation (RVO), but not when
it comes to Named Return Value Optimisation (NRVO).

Of the 27 platforms this is tested and working on, I've had to write
implementations in assembler for 4 of them: arm64, m68k, hppa, sh4.

I could spend another month on this paper but I need to think
"progress not perfection" and release a draft. In the next draft I'll
deal with:
    (1) Ensuring correct use of 'noexcept' with
std::function<void(void)noexcept>
    (2) Use concepts or SFINAE to make sure the class is nonmovable
and noncopyable
No. 2 is important because some of the calling conventions will return
in registers unless the class is unmovable and uncopyable.

I have 27 workflows up on Github which show it tested and working on
various operating systems, compilers and CPU's:
https://github.com/healytpk/nrvo

The PDF file of my paper is attached to this email, and you can also
download the latest draft from:

    http://virjacode.com/downloads/nrvo/paper_nrvo_latest.pdf

File attached: paper_nrvo_draft001.pdf
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals