* Vlad Zahorodnii:

> However, the issue with the former API design is that it's not quite
> the same as the latter design because extra Point objects are created
> with it, see https://godbolt.org/z/xc5E3dbjs. Ideally, Point(x, y)
> would be constructed in foo right away, and then .translated() +
> .scaled() would operate with foo's memory, but it looks like it's not
> the case.

This is more a question for gcc-help.

I think the C++ technique for this is called “expression templates”.  In
some cases, it's possible to get the same effect with moves, but as you
noticed, the destructor (and constructor) calls still happen.

The generated code in <https://godbolt.org/z/hrWs4hbsd> is quite bad,
though: The std::ostream operations should not have been inlined into
Point::~Point.

Thanks,
Florian

Reply via email to