diff --git a/CHANGELOG.md b/CHANGELOG.md index f4014ace..edd7805b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 179: + +* Use the exchange() idiom in move constructors + +-------------------------------------------------------------------------------- + Version 178: * Use static_cast instead diff --git a/include/boost/beast/core/impl/file_posix.ipp b/include/boost/beast/core/impl/file_posix.ipp index 2370e35f..8136bb83 100644 --- a/include/boost/beast/core/impl/file_posix.ipp +++ b/include/boost/beast/core/impl/file_posix.ipp @@ -24,6 +24,7 @@ # endif #endif +#include #include #include #include @@ -65,9 +66,8 @@ file_posix:: inline file_posix:: file_posix(file_posix&& other) - : fd_(other.fd_) + : fd_(boost::exchange(other.fd_, -1)) { - other.fd_ = -1; } inline diff --git a/include/boost/beast/core/impl/file_stdio.ipp b/include/boost/beast/core/impl/file_stdio.ipp index 60a0f3fc..531a8b47 100644 --- a/include/boost/beast/core/impl/file_stdio.ipp +++ b/include/boost/beast/core/impl/file_stdio.ipp @@ -10,6 +10,7 @@ #ifndef BOOST_BEAST_CORE_IMPL_FILE_STDIO_IPP #define BOOST_BEAST_CORE_IMPL_FILE_STDIO_IPP +#include #include namespace boost { @@ -26,9 +27,8 @@ file_stdio:: inline file_stdio:: file_stdio(file_stdio&& other) - : f_(other.f_) + : f_(boost::exchange(other.f_, nullptr)) { - other.f_ = nullptr; } inline diff --git a/include/boost/beast/core/impl/file_win32.ipp b/include/boost/beast/core/impl/file_win32.ipp index 787b0781..1183e385 100644 --- a/include/boost/beast/core/impl/file_win32.ipp +++ b/include/boost/beast/core/impl/file_win32.ipp @@ -10,6 +10,7 @@ #ifndef BOOST_BEAST_CORE_IMPL_FILE_WIN32_IPP #define BOOST_BEAST_CORE_IMPL_FILE_WIN32_IPP +#include #include #include #include @@ -61,9 +62,8 @@ file_win32:: inline file_win32:: file_win32(file_win32&& other) - : h_(other.h_) + : h_(boost::exchange(other.h_, boost::winapi::INVALID_HANDLE_VALUE_)) { - other.h_ = boost::winapi::INVALID_HANDLE_VALUE_; } inline diff --git a/include/boost/beast/core/impl/flat_buffer.ipp b/include/boost/beast/core/impl/flat_buffer.ipp index ffca651c..a3801c67 100644 --- a/include/boost/beast/core/impl/flat_buffer.ipp +++ b/include/boost/beast/core/impl/flat_buffer.ipp @@ -10,6 +10,7 @@ #ifndef BOOST_BEAST_IMPL_FLAT_BUFFER_HPP #define BOOST_BEAST_IMPL_FLAT_BUFFER_HPP +#include #include #include #include @@ -86,18 +87,14 @@ basic_flat_buffer:: basic_flat_buffer(basic_flat_buffer&& other) : detail::empty_base_optimization( std::move(other.member())) - , begin_(other.begin_) - , in_(other.in_) - , out_(other.out_) + , begin_(boost::exchange(other.begin_, nullptr)) + , in_(boost::exchange(other.in_, nullptr)) + , out_(boost::exchange(other.out_, nullptr)) , last_(out_) - , end_(other.end_) + , end_(boost::exchange(other.end_, nullptr)) , max_(other.max_) { - other.begin_ = nullptr; - other.in_ = nullptr; - other.out_ = nullptr; other.last_ = nullptr; - other.end_ = nullptr; } template diff --git a/include/boost/beast/core/impl/multi_buffer.ipp b/include/boost/beast/core/impl/multi_buffer.ipp index a6459d5f..0b35decd 100644 --- a/include/boost/beast/core/impl/multi_buffer.ipp +++ b/include/boost/beast/core/impl/multi_buffer.ipp @@ -11,6 +11,7 @@ #define BOOST_BEAST_IMPL_MULTI_BUFFER_IPP #include +#include #include #include #include @@ -462,20 +463,16 @@ basic_multi_buffer(basic_multi_buffer&& other) : detail::empty_base_optimization< base_alloc_type>(std::move(other.member())) , max_(other.max_) - , in_size_(other.in_size_) - , in_pos_(other.in_pos_) - , out_pos_(other.out_pos_) - , out_end_(other.out_end_) + , in_size_(boost::exchange(other.in_size_, 0)) + , in_pos_(boost::exchange(other.in_pos_, 0)) + , out_pos_(boost::exchange(other.out_pos_, 0)) + , out_end_(boost::exchange(other.out_end_, 0)) { auto const at_end = other.out_ == other.list_.end(); list_ = std::move(other.list_); out_ = at_end ? list_.end() : other.out_; - other.in_size_ = 0; other.out_ = other.list_.end(); - other.in_pos_ = 0; - other.out_pos_ = 0; - other.out_end_ = 0; } template diff --git a/include/boost/beast/http/impl/fields.ipp b/include/boost/beast/http/impl/fields.ipp index a07fd0fa..aca61d2f 100644 --- a/include/boost/beast/http/impl/fields.ipp +++ b/include/boost/beast/http/impl/fields.ipp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -363,11 +364,9 @@ basic_fields(basic_fields&& other) noexcept std::move(other.member())) , set_(std::move(other.set_)) , list_(std::move(other.list_)) - , method_(other.method_) - , target_or_reason_(other.target_or_reason_) + , method_(boost::exchange(other.method_, {})) + , target_or_reason_(boost::exchange(other.target_or_reason_, {})) { - other.method_ = {}; - other.target_or_reason_ = {}; } template diff --git a/include/boost/beast/websocket/detail/stream_base.hpp b/include/boost/beast/websocket/detail/stream_base.hpp index db89dd17..4da5747e 100644 --- a/include/boost/beast/websocket/detail/stream_base.hpp +++ b/include/boost/beast/websocket/detail/stream_base.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -50,9 +51,8 @@ public: soft_mutex& operator=(soft_mutex const&) = delete; soft_mutex(soft_mutex&& other) noexcept - : id_(other.id_) + : id_(boost::exchange(other.id_, 0)) { - other.id_ = 0; } soft_mutex& operator=(soft_mutex&& other) noexcept @@ -156,12 +156,7 @@ struct stream_prng } prng_ref(prng_ref&& other) - : p_([&other] - { - auto p = other.p_; - other.p_ = nullptr; - return p; - }()) + : p_(boost::exchange(other.p_, nullptr)) { }