[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Automatially move from $n (was: C++11 move semantics)
From: |
Hans Åberg |
Subject: |
Re: Automatially move from $n (was: C++11 move semantics) |
Date: |
Sat, 15 Sep 2018 21:19:08 +0200 |
> On 15 Sep 2018, at 20:19, Frank Heckenbach <address@hidden> wrote:
>
> Hans Åberg wrote:
>
>> One idea might be to wrap the actions in inlines, and use return instead, as
>> C++ can recognize r-values in such situations.
>
> I think we discussed this before, but this would only cover the case
> "$$ = $N" (which is covered by the default action for N = 1 anyway).
>
> More interesting are cases such as:
>
> $$ = make_unique <foo> ($1, $2, $3);
The idea would be to write something equivalent to
return make_unique<foo>($1, $2, $3);
and the Bison writes something like
$$ = std::move(action_k(…return make_unique<foo>($1, $2, $3);…))
Even in view of copy elision, default in C++17 [1], this would be safe, because
one cannot move an already moved object by mistake.
As the point is breaking out of the execution path, one might use your
suggestion of a special operator in combination with an immediately following
break in the action switch statement. So writing say
$$$(make_unique<foo>($1, $2, $3));
translates into
$$ = std::move(make_unique<foo>($1, $2, $3));
break;
1. https://en.cppreference.com/w/cpp/language/copy_elision
- Re: Automatially move from $n (was: C++11 move semantics), Akim Demaille, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Frank Heckenbach, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Hans Åberg, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Frank Heckenbach, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics),
Hans Åberg <=
- Re: Automatially move from $n (was: C++11 move semantics), Frank Heckenbach, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Hans Åberg, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Frank Heckenbach, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Hans Åberg, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Frank Heckenbach, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Hans Åberg, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Frank Heckenbach, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Hans Åberg, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Frank Heckenbach, 2018/09/15
- Re: Automatially move from $n (was: C++11 move semantics), Hans Åberg, 2018/09/15