From 5fa47044563adce83aa59b146b738d5c961817c7 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 27 Mar 2019 19:07:51 +1100 Subject: [PATCH] win32/handle: add move operators --- win32/handle.cpp | 24 ++++++++++++++++-------- win32/handle.hpp | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/win32/handle.cpp b/win32/handle.cpp index 2d81b172..f906b800 100644 --- a/win32/handle.cpp +++ b/win32/handle.cpp @@ -17,14 +17,6 @@ handle::handle (HANDLE &&h): { ; } -//----------------------------------------------------------------------------- -handle::handle (handle &&rhs): - m_native (rhs.m_native) -{ - rhs.m_native = nullptr; -} - - //----------------------------------------------------------------------------- handle::handle (posix::fd &&rhs): m_native (reinterpret_cast (_get_osfhandle (rhs.release ()))) @@ -33,6 +25,22 @@ handle::handle (posix::fd &&rhs): } +//----------------------------------------------------------------------------- +handle::handle (cruft::win32::handle &&rhs) noexcept + : handle () +{ + std::swap (m_native, rhs.m_native); +} + + +//----------------------------------------------------------------------------- +handle& handle::operator= (handle &&rhs) noexcept +{ + std::swap (m_native, rhs.m_native); + return *this; +} + + //----------------------------------------------------------------------------- handle::~handle () { diff --git a/win32/handle.hpp b/win32/handle.hpp index 226e6cb2..18e26b61 100644 --- a/win32/handle.hpp +++ b/win32/handle.hpp @@ -17,7 +17,9 @@ namespace cruft::win32 { handle (); explicit handle (posix::fd&&); explicit handle (HANDLE&&); - handle (handle&&); + + handle (handle&&) noexcept; + handle& operator= (handle&&) noexcept; handle (const handle&) = delete; handle& operator= (handle const&) = delete;