Date: Sat, 7 Oct 2023 16:38:59 +0300
On Sat, 7 Oct 2023 at 16:26, Timur Doumler <cpp_at_[hidden]> wrote:
> > On 7 Oct 2023, at 16:10, Ville Voutilainen <ville.voutilainen_at_[hidden]> wrote:
> > That's certainly a possible work-around, but it also always incurs the
> > cost of the copy, even though
> > you really need the copy only when the contract is checked.
>
> What if the return type is non-copyable non-movable, such as a std::atomic? Not really an issue in C I guess, but definitely an issue in C++. This is one of the reasons why in C++, a fully-featured postcondition facility is impossible to implement with macros and requires a new language feature.
For that kind of types, you'll need to do something different from
just a plain copy in the 'capture', so just do the same thing for the
work-around.
All the capture-facility does is provide syntax sugar for a particular
code transformation, so you could just write that transformation in
the function
body manually.
> > On 7 Oct 2023, at 16:10, Ville Voutilainen <ville.voutilainen_at_[hidden]> wrote:
> > That's certainly a possible work-around, but it also always incurs the
> > cost of the copy, even though
> > you really need the copy only when the contract is checked.
>
> What if the return type is non-copyable non-movable, such as a std::atomic? Not really an issue in C I guess, but definitely an issue in C++. This is one of the reasons why in C++, a fully-featured postcondition facility is impossible to implement with macros and requires a new language feature.
For that kind of types, you'll need to do something different from
just a plain copy in the 'capture', so just do the same thing for the
work-around.
All the capture-facility does is provide syntax sugar for a particular
code transformation, so you could just write that transformation in
the function
body manually.
Received on 2023-10-07 13:39:13