diff --git a/include/boost/asio/basic_serial_port.hpp b/include/boost/asio/basic_serial_port.hpp index e18efdd5..f3e91bdb 100644 --- a/include/boost/asio/basic_serial_port.hpp +++ b/include/boost/asio/basic_serial_port.hpp @@ -292,6 +292,55 @@ public: impl_ = std::move(other.impl_); return *this; } + + // All serial ports have access to each other's implementations. + template + friend class basic_serial_port; + + /// Move-construct a basic_serial_port from a serial port of another executor + /// type. + /** + * This constructor moves a serial port from one object to another. + * + * @param other The other basic_serial_port object from which the move will + * occur. + * + * @note Following the move, the moved-from object is in the same state as if + * constructed using the @c basic_serial_port(const executor_type&) + * constructor. + */ + template + basic_serial_port(basic_serial_port&& other, + typename constraint< + is_convertible::value, + defaulted_constraint + >::type = defaulted_constraint()) + : impl_(std::move(other.impl_)) + { + } + + /// Move-assign a basic_serial_port from a serial port of another executor + /// type. + /** + * This assignment operator moves a serial port from one object to another. + * + * @param other The other basic_serial_port object from which the move will + * occur. + * + * @note Following the move, the moved-from object is in the same state as if + * constructed using the @c basic_serial_port(const executor_type&) + * constructor. + */ + template + typename constraint< + is_convertible::value, + basic_serial_port& + >::type operator=(basic_serial_port&& other) + { + basic_serial_port tmp(std::move(other)); + impl_ = std::move(tmp.impl_); + return *this; + } #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) /// Destroys the serial port. diff --git a/test/serial_port.cpp b/test/serial_port.cpp index 9fc30504..48ac6031 100644 --- a/test/serial_port.cpp +++ b/test/serial_port.cpp @@ -85,6 +85,9 @@ void test() #if defined(BOOST_ASIO_HAS_MOVE) serial_port port7(std::move(port6)); + + basic_serial_port port8(ioc); + serial_port port9(std::move(port8)); #endif // defined(BOOST_ASIO_HAS_MOVE) // basic_serial_port operators. @@ -92,6 +95,7 @@ void test() #if defined(BOOST_ASIO_HAS_MOVE) port1 = serial_port(ioc); port1 = std::move(port2); + port1 = std::move(port8); #endif // defined(BOOST_ASIO_HAS_MOVE) // basic_io_object functions. @@ -104,8 +108,8 @@ void test() serial_port::lowest_layer_type& lowest_layer = port1.lowest_layer(); (void)lowest_layer; - const serial_port& port8 = port1; - const serial_port::lowest_layer_type& lowest_layer2 = port8.lowest_layer(); + const serial_port& port10 = port1; + const serial_port::lowest_layer_type& lowest_layer2 = port10.lowest_layer(); (void)lowest_layer2; port1.open("null");