[Development] What's the status of a moved-from object?
Konstantin Ritt
ritt.ks at gmail.com
Tue May 21 13:03:34 CEST 2019
вт, 21 мая 2019 г., 11:32 Mutz, Marc via Development <
development at qt-project.org>:
> And while the partially-formed
> state can be extended to non-pimpled classes easily:
>
> class QRect {
> int x, y, w, h;
> public:
> QRect() = default;
> };
> QRect r; // partially-formed
> r.x(); // compilers _already_ warn about this
> QRect r = {}; // zero-initialized
>
> That
> should be modelled by optional<QRect>, not by QRect itself.
>
Whilst the statement feels reasonable, this will require tons of API
changes and double checks on the user side:
optional<QRect> Item::childrenRect() const
{
if (hasChildren()) {
QRect r = {};
for (auto *child : children())
r.unite(child->boundingRect().value_or({});
return r;
}
return nullopt;
}
QRect r = item->boundingRect().value_or({});
if (!r.isEmpty())
~~~
Note that I'm ok with that, but should we enforce such a huge efforts all
over Qt API just for making the default-constructible QRect a no-op?
Konstantin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20190521/9fedf285/attachment.html>
More information about the Development
mailing list