C++ Logo

std-discussion

Advanced search

Re: std::launder question

From: Ryan Nicholl <exaeta_at_[hidden]>
Date: Mon, 21 Feb 2022 23:05:19 +0000
My question is only if

*std::launder(foo_array+5)

is interchangable with:

std::launder(foo_array)[5]

-------- Original Message --------
On Feb 21, 2022, 16:56, wrote:

> On 22/02/2022 00:35, Ryan Nicholl via Std-Discussion wrote:
>> Assuming that we allocate some storage such that there is space for multiple T e.g.
>>
>> T* foo_array = (T*) malloc(sizeof(foo)*20);
>>
>> Then if we construct
>>
>> new (foo_array+5) T(...);
>> then
>> *std::launder(foo_array+5)
>> is valid
>>
>> But is
>>
>> std::launder(foo_array)[5]
>>
>> also valid?
>
> Depends on T. If it is not an implicit-lifetime type, then you would violate https://timsong-cpp.github.io/cppwp/n4868/ptr.launder#2.sentence-2
> Also, you don't need std::launder in the first case.

Received on 2022-02-21 23:05:32