C++ Logo


Advanced search

Re: [std-proposals] explicit modifier for R-value references

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 19 Jun 2023 15:57:01 +0300
On Mon, 19 Jun 2023 at 14:28, Edward Catmur via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>> You could use it in function parameters as well:
>> void SetVector( vector<int> &&explicit arg )
>> {
>> static vector<int> vec;
>> vec = arg; // no need for 'move' here
>> }
>> Furthermore, when used with a template, it could eradicate the need
>> for "std::forward" as follows:
>> template<typename T>
>> void SetVector( T &&explicit arg )
>> {
>> static T obj;
>> vec = arg; // no need for 'forward' here
>> }
> That sounds feasible, and moderately useful. It wouldn't change the type, correct (and especially not the function type)? - it would just change the result of the value category computed by http://eel.is/c++draft/expr.prim.id#unqual-3.sentence-6 .
> If you're using it on universal references you'll have to say what it means when applied to an lvalue reference as well.
> Would it be applicable to class data members? Non-type template parameters?

I completely fail to see what is "explicit" about any of this. It's
the polar opposite of explicit. Lvalues need to be explicitly
moved-from, this suggestion makes them implicitly movable when the
decltype of such an lvalue is an rvalue reference.

And yes, I get it, I understand that it's using a keyword in order to
avoid an ambiguity if a name is left out. That doesn't
mean that 'explicit' is a good choice for such a keyword, or even an
acceptable choice.

Received on 2023-06-19 12:57:15