From 513212c5e82a40c5e71e5c1758fedf5f12f6c7cf Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 19 Sep 2017 19:55:16 +0200 Subject: [PATCH] input/async: use std::exchange() --- src/input/AsyncInputStream.cxx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/input/AsyncInputStream.cxx b/src/input/AsyncInputStream.cxx index 22d0a309a..ecccf9f65 100644 --- a/src/input/AsyncInputStream.cxx +++ b/src/input/AsyncInputStream.cxx @@ -50,8 +50,7 @@ AsyncInputStream::~AsyncInputStream() void AsyncInputStream::SetTag(Tag *_tag) noexcept { - delete tag; - tag = _tag; + delete std::exchange(tag, _tag); } void @@ -77,11 +76,9 @@ AsyncInputStream::Resume() void AsyncInputStream::Check() { - if (postponed_exception) { - auto e = std::move(postponed_exception); - postponed_exception = std::exception_ptr(); - std::rethrow_exception(e); - } + if (postponed_exception) + std::rethrow_exception(std::exchange(postponed_exception, + std::exception_ptr())); } bool @@ -154,9 +151,7 @@ AsyncInputStream::SeekDone() noexcept Tag * AsyncInputStream::ReadTag() { - Tag *result = tag; - tag = nullptr; - return result; + return std::exchange(tag, nullptr); } bool