Use gsl::finally() instead of base::scope_guard().

This commit is contained in:
John Preston 2017-08-13 19:16:48 +03:00
parent 012d59ab42
commit 17cef93ac0
7 changed files with 8 additions and 35 deletions

View file

@ -109,31 +109,6 @@ inline constexpr D up_cast(T object) {
return internal::up_cast_helper<D>(std::integral_constant<bool, std::is_base_of<DV, TV>::value || std::is_same<DV, TV>::value>(), object);
}
template <typename Lambda>
class scope_guard_helper {
public:
scope_guard_helper(Lambda on_scope_exit) : _handler(std::move(on_scope_exit)) {
}
void dismiss() {
_dismissed = true;
}
~scope_guard_helper() {
if (!_dismissed) {
_handler();
}
}
private:
Lambda _handler;
bool _dismissed = false;
};
template <typename Lambda>
scope_guard_helper<Lambda> scope_guard(Lambda on_scope_exit) {
return scope_guard_helper<Lambda>(std::move(on_scope_exit));
}
template <typename Container, typename T>
inline bool contains(const Container &container, const T &value) {
auto end = std::end(container);

View file

@ -538,12 +538,11 @@ bool Widget::Step::paintAnimated(Painter &p, QRect clip) {
return true;
}
auto guard = base::scope_guard([this, &p] {
if (hasCover()) paintCover(p, 0);
});
auto dt = _a_show.current(getms(), 1.);
if (!_a_show.animating()) {
if (hasCover()) {
paintCover(p, 0);
}
if (_coverAnimation.title) {
showFinished();
}
@ -561,7 +560,6 @@ bool Widget::Step::paintAnimated(Painter &p, QRect clip) {
auto coverTop = (hasCover() ? anim::interpolate(-st::introCoverHeight, 0, showCoverMethod) : anim::interpolate(0, -st::introCoverHeight, hideCoverMethod));
paintCover(p, coverTop);
guard.dismiss();
auto positionReady = hasCover() ? showCoverMethod : hideCoverMethod;
_coverAnimation.title->paintFrame(p, positionReady, departingAlpha, arrivingAlpha);

View file

@ -186,7 +186,7 @@ void LayerStackWidget::BackgroundWidget::paintEvent(QPaintEvent *e) {
Painter p(this);
_inPaintEvent = true;
auto guard = base::scope_guard([this] {
auto guard = gsl::finally([this] {
_inPaintEvent = false;
checkIfDone();
});

View file

@ -247,7 +247,7 @@ QString GetServerName() {
}
gchar *name = nullptr;
auto guard = base::scope_guard([&name] {
auto guard = gsl::finally([&name] {
if (name) Libs::g_free(name);
});

View file

@ -659,7 +659,7 @@ int32 MainWindow::screenNameChecksum(const QString &name) const {
void MainWindow::psRefreshTaskbarIcon() {
auto refresher = object_ptr<QWidget>(this);
auto guard = base::scope_guard([&refresher] {
auto guard = gsl::finally([&refresher] {
refresher.destroy();
});
refresher->setWindowFlags(static_cast<Qt::WindowFlags>(Qt::Tool) | Qt::FramelessWindowHint);

View file

@ -83,7 +83,7 @@ void ScaleWidget::onAutoChanged() {
void ScaleWidget::setScale(DBIScale newScale) {
if (_inSetScale) return;
_inSetScale = true;
auto guard = base::scope_guard([this] { _inSetScale = false; });
auto guard = gsl::finally([this] { _inSetScale = false; });
if (newScale == cScreenScale()) newScale = dbisAuto;
if (newScale == dbisAuto && !_auto->checked()) {

View file

@ -176,7 +176,7 @@ void Manager::stopAllHiding() {
}
void Manager::showNextFromQueue() {
auto guard = base::scope_guard([this] {
auto guard = gsl::finally([this] {
if (_positionsOutdated) {
moveWidgets();
}