[v3 PATCH] Implement LWG 2857, {variant,optional,any}::emplace should return the constructed value.
Jonathan Wakely
jwakely@redhat.com
Wed Mar 15 23:05:00 GMT 2017
On 16/03/17 00:43 +0200, Ville Voutilainen wrote:
>On 16 March 2017 at 00:31, Jonathan Wakely <jwakely@redhat.com> wrote:
>>> emplace(_Args&&... __args)
>>> {
>>> __do_emplace<_Decay<_ValueType>>
>>> (std::forward<_Args>(__args)...);
>>> + return *(std::any_cast<_Decay<_ValueType>>(this));
>>
>>
>> Can we avoid the branch in any_cast to check the stored type?
>> We know it's the right type, because we just stored it.
>
>While I would hope the compiler to be smart enough to realize some of
>that (we are passing in
>this), the other branches might not be so easy. But certainly, we can
>axe every one of the extraneous
>branches, like in the attached amendment.
And then we don't need the forward declarations of any and any_ast,
right?
OK for trunk like that, thanks.
More information about the Libstdc++
mailing list