C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] std::duplicate
From: Michael Daum (mike.daum_at_[hidden])
Date: 2019-10-03 08:25:33


The big difference to me is that decay_copy doesn't forward rvalue refs, it
always returns a value. So it's a lot like `auto{v}` or pass by value in
that it can generate an extra move.
(Example <https://godbolt.org/z/c0QNpU>)

So to me I'd rather get this in as a new function than try to "lift"
decay_copy from exposition only into the actual library.

On Wed, Oct 2, 2019 at 10:45 PM Tam S. B. via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> That's effectively decay_copy. (http://eel.is/c++draft/expos.only.func )
>
> ________________________________________
> From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of
> Michael Daum via Std-Proposals <std-proposals_at_[hidden]>
> Sent: Wednesday, October 2, 2019 4:03:21 PM
> To: std-proposals_at_[hidden]
> Cc: Michael Daum
> Subject: [std-proposals] std::duplicate
>
> I've become quite fond of a utility called `CopyTemp` which exists in the
> Unreal Engine code base. So much so that I think that it should be
> standardized. For lack of a better name, I'll call it `std::duplicate`.
>
> Like std::move, std::duplicate would take an argument of any value
> category and provide a return which is an rvalue. However, std::duplicate
> would accomplish this by copying when it had to. Sample Implementation<
> https://godbolt.org/z/7nIJNT>
>
> Once we have this utility, we are able to say that the best practice for
> providing a sink parameter is to declare it with rvalue reference type.
> Attempts to call the sink with lvalue arguments will cause a compiler error
> forcing to caller to either `std::move` or `std::duplicate` the arg when
> passed into the call. Compilers would be able to provide very clean,
> readable errors if they wanted to, and the resulting code would be optimal
> in terms of number of copies and moves.
> Example<https://godbolt.org/z/Q_E_J->
>
> The strengths of this proposal are:
> - It is library only
> - It is tiny, self contained, and easy to implement
> - Helps solve a problem for which we have no great best practice (sink
> parameters) in a teachable, optimal way which actually makes the calling
> code more safe and readable
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>



STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups