From e842a060f11c564ba8cd30b9044dcad09cc28bf0 Mon Sep 17 00:00:00 2001 From: Jonas Greitemann Date: Sun, 12 Jan 2025 20:08:36 +0100 Subject: [PATCH] implement move operations for `process_io_binding` and delete copy operations This makes the test added in the previous commit pass. --- include/boost/process/v2/stdio.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/boost/process/v2/stdio.hpp b/include/boost/process/v2/stdio.hpp index ddd4fcea..f1bf0804 100644 --- a/include/boost/process/v2/stdio.hpp +++ b/include/boost/process/v2/stdio.hpp @@ -166,6 +166,31 @@ struct process_io_binding } process_io_binding() = default; + process_io_binding(const process_io_binding &) = delete; + process_io_binding & operator=(const process_io_binding &) = delete; + + process_io_binding(process_io_binding && other) noexcept + : fd(other.fd), fd_needs_closing(other.fd), ec(other.ec) + { + other.fd = target; + other.fd_needs_closing = false; + other.ec = {}; + } + + process_io_binding & operator=(process_io_binding && other) noexcept + { + if (fd_needs_closing) + ::close(fd); + + fd = other.fd; + fd_needs_closing = other.fd_needs_closing; + ec = other.ec; + + other.fd = target; + other.fd_needs_closing = false; + other.ec = {}; + return *this; + } template process_io_binding(Stream && str, decltype(std::declval().native_handle()) * = nullptr)