Changeset View
Changeset View
Standalone View
Standalone View
kcm/output_model.h
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | |||||
82 | 82 | | |||
83 | private: | 83 | private: | ||
84 | struct Output { | 84 | struct Output { | ||
85 | Output() {} | 85 | Output() {} | ||
86 | Output(const Output &output) | 86 | Output(const Output &output) | ||
87 | : ptr(output.ptr) | 87 | : ptr(output.ptr) | ||
88 | , pos(output.pos) | 88 | , pos(output.pos) | ||
89 | {} | 89 | {} | ||
90 | Output(Output &&) noexcept = default; | ||||
romangg: Why to add and why noexcept? | |||||
Because in output_model.cpp:224 we do m_outputs.insert(i, Output(output, pos)), which can make use of move semantics. Making move operations noexcept is part of Cpp Core Guidelines and because QSharedPointer's move ctor is noexcept and QPoint is trivially movable, the move operations here are also noexcept. If it has any benefit here, since we possibly don't even have exceptions enabled in kscreen, is a question - I wrote it by force of habit. dvratil: Because in `output_model.cpp:224` we do `m_outputs.insert(i, Output(output, pos))`, which can… | |||||
Thanks for the interesting explanation. I find it impractical that the usefulness of the noexcept keyword here depends on internals of the Qt classes. One would wish this is advertised to the consumer without knowing the internals. Or is it somewhere I'm not aware of? romangg: Thanks for the interesting explanation. I find it impractical that the usefulness of the… | |||||
90 | Output(KScreen::OutputPtr _ptr, const QPoint &_pos) | 91 | Output(KScreen::OutputPtr _ptr, const QPoint &_pos) | ||
91 | : ptr(_ptr) | 92 | : ptr(_ptr) | ||
92 | , pos(_pos) | 93 | , pos(_pos) | ||
93 | {} | 94 | {} | ||
95 | Output &operator=(const Output &output) { | ||||
96 | ptr = output.ptr; | ||||
97 | pos = output.pos; | ||||
98 | posReset = QPoint(-1, -1); | ||||
99 | return *this; | ||||
100 | } | ||||
101 | Output &operator=(Output &&) noexcept = default; | ||||
102 | | ||||
94 | KScreen::OutputPtr ptr; | 103 | KScreen::OutputPtr ptr; | ||
95 | QPoint pos; | 104 | QPoint pos; | ||
96 | QPoint posReset = QPoint(-1, -1); | 105 | QPoint posReset = QPoint(-1, -1); | ||
97 | }; | 106 | }; | ||
98 | 107 | | |||
99 | void roleChanged(int outputId, OutputRoles role); | 108 | void roleChanged(int outputId, OutputRoles role); | ||
100 | 109 | | |||
101 | void resetPosition(const Output &output); | 110 | void resetPosition(const Output &output); | ||
Show All 39 Lines |
Why to add and why noexcept?