From 0a78d8ea3c7dbb29a39f6cb2ae98710058f5b3a2 Mon Sep 17 00:00:00 2001 From: Matthias Moulin Date: Mon, 7 Oct 2019 21:49:50 +0200 Subject: [PATCH] Added std::exchange (C++14) to make the intent more explicit --- include/gsl/gsl_util | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/gsl/gsl_util b/include/gsl/gsl_util index 0fce689..e4b2daa 100644 --- a/include/gsl/gsl_util +++ b/include/gsl/gsl_util @@ -24,7 +24,7 @@ #include // for exception #include // for initializer_list #include // for is_signed, integral_constant -#include // for forward +#include // for exchange, forward #if defined(_MSC_VER) && !defined(__clang__) @@ -59,10 +59,7 @@ class final_action public: explicit final_action(F f) noexcept : f_(std::move(f)) {} - final_action(final_action&& other) noexcept : f_(std::move(other.f_)), invoke_(other.invoke_) - { - other.invoke_ = false; - } + final_action(final_action&& other) noexcept : f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false)) {} final_action(const final_action&) = delete; final_action& operator=(const final_action&) = delete;